如何在更新字段时检查字段中的空字符串和空字符串? [英] How to check for null and empty string in the field while updating the field ?

查看:85
本文介绍了如何在更新字段时检查字段中的空字符串和空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的要求是我有程序,



现在基于我想要的参数更新我的表,



但是我想检查这些参数是否为空或空白或空我只想在使用sql更新我的表时保留旧记录查询'



请建议

Hi ,

My requirment is I have procedure ,

Now based on paramters I want to update my table ,

however I want to check if any of those parameters are null or blank or empty I wanted to keep old records only while updating my table using sql query '

please suggest

推荐答案

您可以使用CASE语句。如果我理解正确,你想在参数为空或空的情况下单独保留字段。



简单地做这样的事情:

You can use a CASE statement. If I understand you correctly, you want to leave the field alone if the parameter is null or empty.

Simply do something like this:
UPDATE table1 
SET field1 = CASE WHEN COALESCE(@field1, '') = '' THEN field1 ELSE @field1 END


这篇关于如何在更新字段时检查字段中的空字符串和空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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