【发布时间】:2017-05-16 23:29:07
【问题描述】:
使用 SQL Server 2016(在 Azure 上)我希望辅助 t2 数据作为数组,以避免主要数据重复。像这样的:
但是我只能用FOR JSON AUTO来做,不能控制属性名...
我怎样才能使用FOR JSON PATH 或类似的方法来控制属性名称?
用于测试的 SQL:
create table #t1 (id bigint, name varchar(20))
create table #t2 (id bigint, idBase bigint, name varchar(20))
insert into #t1 values (1,'teste1')
insert into #t1 values (2,'teste2')
insert into #t2 values (1,1,'teste11')
insert into #t2 values (2,1,'teste21')
insert into #t2 values (3,2,'teste32')
select
t1.id as 'base.id'
,t1.name as 'base.name'
,t2.id as 'base.secondary.id'
,t2.name as 'base.secondary.name'
from
#t1 as t1
inner join
#t2 as t2 on t1.id = t2.idBase
for json auto
谢谢!
【问题讨论】:
-
我对此进行了测试,只更改了最后一行,例如
FOR JSON PATH,而查询中没有任何更改,并且为我工作!
标签: json sql-server-2016