【发布时间】:2022-01-15 09:42:27
【问题描述】:
使用 PostgreSQL,我可以拥有多行 json 对象。
select (select ROW_TO_JSON(_) from (select c.name, c.age) as _) as jsonresult from employee as c
这给了我这个结果:
{"age":65,"name":"NAME"}
{"age":21,"name":"SURNAME"}
但是在 SqlServer 中,当我使用 FOR JSON AUTO 子句时,它给了我一个 json 对象数组而不是多行。
select c.name, c.age from customer c FOR JSON AUTO
[{"age":65,"name":"NAME"},{"age":21,"name":"SURNAME"}]
如何在SqlServer中得到相同的结果格式?
【问题讨论】:
-
SQL Server 2016 CTP3.2 添加了
without_array_wrapper...示例:select top 5 (select a.* for json path, without_array_wrapper) from sys.objects a
标签: sql-server sql-server-2016