sql读取数据并返回json
/*
INCLUDE_NULL_VALUES:为空也显示
WITHOUT_ARRAY_WRAPPER:结果集不以数组展示,默认json数组
*/
select top 10 *
from [dbo].student
FOR JSON AUTO, INCLUDE_NULL_VALUES,WITHOUT_ARRAY_WRAPPER
/* 返回主子结构的json数据
*/
select
sex,
json_query((
select name,age,birthday
from dbo.student carsInner
where carsInner.sex=carsOuter.sex
for json path
)) as 人员
from dbo.student carsOuter
group by sex
for json path;
文章介绍了如何使用SQL查询从数据库中获取数据,并通过FORJSON功能将其转换为JSON格式,包括处理NULL值和生成主子结构的示例。
949

被折叠的 条评论
为什么被折叠?



