使用 FOR JSON 將查詢結果格式化為 JSON
輸入表資料(人員表)
ID |
Name | 年齡 |
---|---|---|
1 |
約翰 | 23 |
2 |
簡 | 31 |
詢問
SELECT Id, Name, Age
FROM People
FOR JSON PATH
結果
[
{"Id":1,"Name":"John","Age":23},
{"Id":2,"Name":"Jane","Age":31}
]
輸入表資料(人員表)
ID |
Name | 年齡 |
---|---|---|
1 |
約翰 | 23 |
2 |
簡 | 31 |
詢問
SELECT Id, Name, Age
FROM People
FOR JSON PATH
結果
[
{"Id":1,"Name":"John","Age":23},
{"Id":2,"Name":"Jane","Age":31}
]