本文介绍了嵌套如果条件不适用于SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if EXISTs(SELECT 1 FROM Framework.Service WHERE ID = 'B0ED76DD-F93B-4B64-8E87-654129E2A8AC' AND DeploymentID = 'D6726F6A-10A0-4917-AFD3-21949A62CD51') begin --print 'x' Update Custom.Membership set membershiptype = 'Unlimited/Ongoing' where Ongoing = 1 end
这里条件为false仍然会尝试设置不存在的membershiptypetype列并抛出错误。
Here condition is false still it tries to set membershiptype column which does not exists and throws the error.
推荐答案使用else部分查看然后如果嵌套查询中的条件,则可以获得缺少的点 See with else part then you can get the point where it is missing if condition in your nested query IF EXISTS(SELECT * FROM Framework.Service WHERE ID = 'B0ED76DD-F93B-4B64-8E87-654129E2A8AC' AND DeploymentID = 'D6726F6A-10A0-4917-AFD3-21949A62CD51') begin --check whether ma package is not installed IF NOT EXISTS(SELECT * FROM Framework.Service WHERE ID = '764AE521-320E-4B90-A9F7-5C7614C5C28E' AND DeploymentID = '3015C5DB-DE04-4B73-89BF-AEDE95F3D9F8') begin if exists (select * from [Framework].[Object] where id = '8AC96BD2-9550-486B-804E-A40D0C57D6EC') begin --go Update Custom.Membership set membershiptype = 'Unlimited/Ongoing' where Ongoing = 1 end else begin select 'else part of last nested if' end end else begin select 'else part of second nested if' end end else begin select 'else part of first nested if' end
我得到了解决方案 - 在这种情况下,我必须使用动态sql。 I got the solution- In this case I have to use dynamic sql.
更多推荐
嵌套如果条件不适用于SQL Server
发布评论