SQL 服务器 JSON 路径

SQL Server FOR JSON PATH

所以,我 table 有这样的数据

PersonID | Name | Address       | Skills
---------+------+---------------+------------
   1     | XYZ  | Test Address  | NA
   2     | ABC  | Test Address2 | Programming

我想使用这样的 SQL 查询将数据转换为 JSON

{
  "PersonID":"1", 
  "Name": "XYZ", 
  "Address" : "Test Address",
  "Skills": [
               {
                   "Name":"NA"
               }
           ]
}

只是嵌套FOR JSON:

SELECT ID,
       [Name],
       Address,
       (SELECT Skill AS Name
        FOR JSON PATH) AS Skills
FROM (VALUES(1,'xyz','yyy','na'))V(ID,[Name],Address,Skill)
FOR JSON PATH;