简体   繁体   English

如何在SQL Server中的nvarchar(max)类型列中存在的json结构中添加新属性

[英]How to add a new property in json structure existing in nvarchar(max) type column in SQL Server

I have data like this in an employee table in a column of type nvarchar(max) : 我在nvarchar(max)类型的列中的employee表中有这样的数据:

{
   "ID":101,
   "FirstName":"Vatan",
   "LastName":"Soni"
}

Now I need to update all rows with FullName property as well, so result should be 现在我需要使用FullName属性更新所有行,因此结果应该是

{
    "ID":101,
    "FirstName":"Vatan",
    "LastName":"Soni",
    "FullName":"Vatan Soni"
}

Please help and provide the SQL update script for it. 请帮助并提供SQL更新脚本。

Thanks in advance. 提前致谢。

Starting with SQL 2016 you have JSON types and functions: JSON_MODIFY : 从SQL 2016开始,您有JSON类型和函数: JSON_MODIFY

UPDATE <table> 
  SET <column> = JSON_MODIFY(<column>, '$.FullName', 
  JSON_VALUE(<column>, '$.FirstName') + ' ' + JSON_VALUE(<column>, '$.LastName'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linq - 从 SQL 服务器中的 nvarchar 类型列中查找最大值 - Linq - Find max value from a nvarchar type column in SQL Server 如何将现有表中的nvarchar列转换为日期? SQL服务器 - How convert nvarchar column from a existing table to date? SQL Server 在 SQL Server 中索引 NVARCHAR(MAX) 列 - Indexing an NVARCHAR(MAX) column in SQL Server 如何在不更改值的情况下将数据从 nvarchar(max) 列移动到 SQL Server 中的 varbinary(max) 列? - How to move data from nvarchar(max) column to varbinary(max) column in SQL server without changing the value? 当列在 Microsoft SQL Server 中为 nvarchar 类型时如何按日期排序 - How to order by date when a column is of type nvarchar in Microsoft SQL Server 如何在SQL Server上的任何列类型上MAX() - How to MAX() on any column type at SQL Server SQL 服务器 json 被截断(即使使用 NVARCHAR(max) ) - SQL Server json truncated (even when using NVARCHAR(max) ) 使用LINQ在SQL Server 2012中查找nvarchar列的最大值 - Finding Max Value of an nvarchar column in sql server 2012 using LINQ SQL 服务器 2017 - 更新 NVARCHAR(MAX) 列导致问号 - SQL Server 2017 - Update NVARCHAR(MAX) column causes question marks 如何将 nvarchar 转换为 SQL 服务器的 int 类型 - How to convert nvarchar into int type for SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM