且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将空值更新为指定值

更新时间:2023-02-17 07:40:29

'''')'' exec(@sql) 更新General_holydays_details设置createddatetime = @getdate,其中createddatetime = null 更新General_holydays_details设置adminid = @ adminid,其中adminid = null 结束
'''')'' exec (@sql) update General_holydays_details set createddatetime= @getdate where createddatetime=null update General_holydays_details set adminid=@adminid where adminid=null end



但是当我执行此存储过程时,仅更新excel文件,并且createddatetime和adminid保留为空值.
但是我通过编码将createddatetime值和adminid传递给了此存储过程.
有什么问题,请找出并帮助我



but when i executing this stored procedure, only excel file is updated and createddatetime and adminid remain null value.
but i pass createddatetime value and adminid to this stored procedure from my coding.
What is the problem please find out and help me


空值永远不会等于(或不等于)任何东西,因此您无法将其与普通运算符进行比较.

在这些情况下,SQL语言具有特殊的运算符IS NULLIS NOT NULL.

因此您的程序应如下所示:
Null is never equal (or unequal) to anything so you cannot compare it with normal operators.

SQL language has special operators IS NULL and IS NOT NULL for these cases.

So your procedure should look like:
...
update General_holydays_details set createddatetime= @getdate where createddatetime is null
update General_holydays_details set adminid=@adminid where adminid is null
...



有关更多信息,请参考 IS [NOT] NULL [空(SQL) [



For more information, refer to IS [NOT] NULL[^] and Null (SQL)[^]