代码改变世界

sql 拼接json

2020-07-06 15:40  su_hq  阅读(991)  评论(0编辑  收藏  举报

select '[' + STUFF((
select top 10
',{"carnumber":"' + cast(carnumber as varchar) + '"'
+ ',"goodsno":"' + cast(goodsno as varchar)+ '"'
+ ',"goods":"' + cast(Goods as varchar) + '"'
+'}'
from OtherWeight t1
for xml path(''),type
).value('.', 'varchar(max)'), 1, 1, '') + ']'

 

 


select '[' + STUFF((
select top 10
',{"carnumber":"' + cast(carnumber as varchar) + '"'
+ ',"goodsno":"' + cast(goodsno as varchar)+ '"'
+ ',"goods":"' + cast(Goods as varchar) + '"'
+'}'
from OtherWeight t1
for xml path('')
), 1, 1, '') + ']'