如何将所有连接表中的所有结果组合为一个JSON输出
我正在加入一些表,使用JSON路径进行输出,但我只想以某种结构化的方式观察所有表的数据。
SELECT
tableOne.attrA AS 'tableOne.attrA',
tableOne.attrB AS 'tableOne.attrB',
...
tableTwo.attrB AS 'tableTwo.attrB'
...
FROM tableOne
JOIN tableTwo
ON tableOne.fId = tableTwo.id
FOR JSON PATH
并获得输出之类的:
{
"tableOne": {
"attrA": "asdf"
}
"tableOne": {
"attrB": "fdsa"
}
}
我想对所有值都有符号,例如:
SELECT
tableOne.* AS 'tableOne.*',
tableTwo.* AS 'tableTwo.*',
tableThree.* AS 'tableThree.*
....
FOR JSON PATH;
我看到json_array
,可以与json_object
结合使用,但它仅在SQL Server 2022中。我有2019版。
I'm joining some tables, using FOR JSON PATH
for output, but I just want to observe data from all the tables in some structured manner.
SELECT
tableOne.attrA AS 'tableOne.attrA',
tableOne.attrB AS 'tableOne.attrB',
...
tableTwo.attrB AS 'tableTwo.attrB'
...
FROM tableOne
JOIN tableTwo
ON tableOne.fId = tableTwo.id
FOR JSON PATH
And get output like:
{
"tableOne": {
"attrA": "asdf"
}
"tableOne": {
"attrB": "fdsa"
}
}
I would like to have somethign for all the values like:
SELECT
tableOne.* AS 'tableOne.*',
tableTwo.* AS 'tableTwo.*',
tableThree.* AS 'tableThree.*
....
FOR JSON PATH;
I saw JSON_ARRAY
which can be combined with JSON_OBJECT
but it's only in SQL Server 2022. I have 2019 version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我找到了解决方案:
这将在形成的JSON中输出所有数据。我会添加一些链接到MS Docu,但稍后。
So I found the solution:
And this outputs all the data in formated JSON. I would add some links to ms docu, but later.