我正在尝试为我目前正在研究的一个新项目创建一个 JSON 文件,我的大部分工作都按预期工作,但我现在正处于尝试使用子查询以正确格式化 JSON。
我尝试使用以下子查询,但 SQL 不喜欢这种格式。
` 选择
'Admin User TEST ONLY PLEASE IGNORE' AS AdditionalNotes
(
SELECT v.atFault
FROM dbo.ic_DP_AX ax
CROSS APPLY (VALUES (ax.Acc_fault1), (ax.Acc_fault2)) v (atFault)
FOR JSON AUTO
) AS InsuredPartyClaims,
(
SELECT Acc_fault3 AS atFault
FROM dbo.ic_DP_AX
FOR JSON AUTO
) AS InsuredPartyConvictions
FOR JSON PATH) ROOT('InsuredParties')
FROM
dbo.icp_Daprospect AS p INNER JOIN
dbo.icp_Dapolicy AS d ON p.Branch@ = d.Branch@ AND p.ClientRef@ =
d.ClientRef@ LEFT OUTER JOIN
dbo.ic_DP_AX AS ax ON P.Branch@ = ax.B@ AND ax.PolRef@ = d.PolicyRef@
LEFT OUTER JOIN
WHERE
d.PolicyRef@ = '' AND
d.Branch@ = 0`
对于 JSON 路径
我想要实现的输出是:
"InsuredParties": [
{
"InsuredPartyClaims": [
{
"atFault": false
},
{
"atFault": true
}
],
"InsuredPartyConvictions": [
{
"atFault": false
},
谁能看到我做错了什么?我试图让这个尽可能简单。