如何在update语句的where子句中使用case子句 [英] How to use case clause in where clause of update statement

查看:219
本文介绍了如何在update语句的where子句中使用case子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,





i想在更新声明的where子句中使用CASE子句



Hi Experts,


i want to use CASE clause within where clause of update statement

IF not exist (select listid from list where Listname=@listname and ListType=@ListType and AccessType=@AccessType AND (CreatedBy = @EmplpyeeID OR @CreatedBy = '0' OR @AccessType = 'Global'))

BEGIN

--some other statement

END







列表结构:list(listid,listname,listname_en,listname_DE,。 ..)

我想使用类似这样的CASE子句...基于@languagecode参数值我想用列表表的不同列(listname_en,listname_de ...)检查@listname值br $> b $ b






List table structure:list(listid,listname,listname_en,listname_DE,...)
I want use CASE clause something like this...Based upon @languagecode parameter value i want to check @listname value with different columns(listname_en,listname_de...) of list table


IF not exist (select listid from list where  
case when @languagecode='en' then ListName_en =@listname 
case when @languagecode='DE' then ListName_DE =@listname and ListType=@ListType and AccessType=@AccessType AND (CreatedBy = @EmplpyeeID OR @CreatedBy = '0' OR @AccessType = 'Global'))

BEGIN

--some other statement

END









上述声明不起作用请给我解决方案。



我将非常感谢你。





the above statement is not working please give me the solution .

I will appreciate you.

推荐答案

尝试这样的事情:



Try something like this:

IF NOT EXIST (SELECT listid FROM list WHERE @languagecode='en' AND ListName_en =@listname AND ListType=@ListType AND AccessType=@AccessType AND (CreatedBy = @EmplpyeeID OR @CreatedBy = '0' OR @AccessType = 'Global'))
 
BEGIN
 
--some other statement

END





你不需要在这种情况下使用案例陈述。您有多个正在检查的值,并且case语句将为每个case语句提供一个结果,因此不适合您的查询。



[更新]



试试这个,它会得到一些你可以在查询运行之前查看的值。





You do not need to use a case statement in this situation. You have multiple values you are checking against and a case statement will give you one result for each case statement so is not appropriate for your query.

[UPDATE]

Try this, it will get some values you can check before the query runs.

DECLARE @listNameChoice varchar(25)

SET @listNameChoice = (Case WHEN @languagecode = 'en' THEN 'ListName_en' ELSE 'ListName_DE' END)

IF NOT EXIST (SELECT listid FROM list WHERE @listNameChoice = @listname AND ListType=@ListType AND AccessType=@AccessType AND (CreatedBy = @EmplpyeeID OR @CreatedBy = '0' OR @AccessType = 'Global'))
 
BEGIN
 
--some other statement

END


IF not exist (select listid from list where  
case @languagecode when 'en' then ListName_en
case @languagecode  when 'DE' then ListName_DE End =@listname and ListType=@ListType and AccessType=@AccessType AND (CreatedBy = @EmplpyeeID OR @CreatedBy = '0' OR @AccessType = 'Global'))
 
BEGIN
 
--some other statement

END

这篇关于如何在update语句的where子句中使用case子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆