gpt4 book ai didi

失败时 SQL 将结果写入 XML

转载 作者:行者123 更新时间:2023-12-04 06:10:29 25 4
gpt4 key购买 nike

 SELECT   
(SELECT v_value as "@value", columnname as "@columnname",
updatedby as "@updatedby", emailid as "@emailid",
updatedon as "@updatedon"
from nodetable, Progresss PGA, mastertable
where columnname ='SSNNO'
and PGA.ProjId=9
AND OBSID IN (SELECT NodeId FROM projecttable
WHERE ParentId=mastertable.roles AND Title='some value')
AND UserId=1
AND mastertable.FileID=nodetable.fileid
AND mastertable.FileID=821
ORDER BY updatedon desc FOR XML PATH('Forms'), TYPE)
FOR XML PATH('Form'), TYPE

这是我获取 XML 的查询..别担心它的工作正常..

但是我的问题如果条件失败我想再打印一个标签,它总是告诉查询中发生了什么..

对于这个查询,如果所有条件都成功,我将获得完整的 XML..

否则我会得到
 <Form />

但我想在失败的情况下打印结果..
<Form SUCCESS="0"/>

最佳答案

DECLARE @XML XML =
(SELECT v_value as "@value", columnname as "@columnname",
updatedby as "@updatedby", emailid as "@emailid",
updatedon as "@updatedon"
from nodetable, Progresss PGA, mastertable
where columnname ='SSNNO'
and PGA.ProjId=9
AND OBSID IN (SELECT NodeId FROM projecttable
WHERE ParentId=mastertable.roles AND Title='some value')
AND UserId=1
AND mastertable.FileID=nodetable.fileid
AND mastertable.FileID=821
ORDER BY updatedon desc FOR XML PATH('Forms'))

IF @XML IS NULL
SELECT CAST('<Form SUCCESS="0"/>' AS XML)
ELSE
SELECT @XML FOR XML PATH('Form')

作为一个声明
SELECT CASE WHEN T.X IS NULL THEN 0 END AS [@SUCCESS],
T.X AS [*]
FROM
(SELECT v_value as "@value", columnname as "@columnname",
updatedby as "@updatedby", emailid as "@emailid",
updatedon as "@updatedon"
from nodetable, Progresss PGA, mastertable
where columnname ='SSNNO'
and PGA.ProjId=9
AND OBSID IN (SELECT NodeId FROM projecttable
WHERE ParentId=mastertable.roles AND Title='some value')
AND UserId=1
AND mastertable.FileID=nodetable.fileid
AND mastertable.FileID=821
ORDER BY updatedon desc FOR XML PATH('Forms'), TYPE) AS T(X)
FOR XML PATH('Form'), TYPE

关于失败时 SQL 将结果写入 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7844501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com