[英]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.