嵌套如果条件不适用于SQL Server

编程入门 行业动态 更新时间:2024-10-13 16:15:19
本文介绍了嵌套如果条件不适用于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

本文发布于:2023-10-26 17:41:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   不适用于   条件   Server   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!