使用多个更新查询的Case语句 [英] Case statement using multiple update queries

查看:77
本文介绍了使用多个更新查询的Case语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



在sql server中我需要根据条件使用

case语句更新单个列。 />
我需要在每次条件失败时将原因连接到我的原因栏上





我试过这样的....





update tbltemp set reason =

case

当len(abc)> 17然后是reason.concat(原因,'abc无效')

当len(def)> 100然后是reason.concat(原因,'def无效')

其他''

结束





最后我需要显示原因如'abc无效,def无效'

如果两个条件失败。





对于上面的查询我得到这样的错误:



无法找到列reason或用户定义的函数或聚合reason.concat,或者名称是不明确的。

感谢提前任何帮助..

解决方案

尝试以下查询。



  update  tbltemp  set  reason = 
case
len(abc)> 17 然后原因+ ' abc无效'
len(def)> 100 然后原因+ ' def无效'
else ' '
结束


访问此处以便了解...



publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlt.doc/sqltmst148.htm

Hello,

In sql server i need to update a single column based on the condition using
case statement..
I need to concat the reason to my reason column every time when the condition fails


I tried like this....


update tbltemp set reason=
case
when len(abc)>17 then reason.concat(reason,'abc not valid')
when len(def)>100 then reason.concat(reason,'def not valid')
else ''
end


at the end i need to display reason like 'abc not valid,def not valid'
if the two conditions fails.


For the above query iam getting error like this:

Cannot find either column "reason" or the user-defined function or aggregate "reason.concat", or the name is ambiguous.
Thanks for any help in advance..

解决方案

Try this below query.

  update tbltemp  set reason=
case 
when len(abc)>17 then reason+'abc not valid'
when len(def)>100 then reason+'def not valid'
else '' 
end 


visit here for example to understand...

publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlt.doc/sqltmst148.htm


这篇关于使用多个更新查询的Case语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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