更新Sql Server中的Null [英] Update Where Null in Sql Server

查看:154
本文介绍了更新Sql Server中的Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用A字符串更新图像列,其中它现在为空..但是

它无法工作...我的查询下面..

任何一个可以解释一下它为什么会发生..



更新信息set image ='Image / defalt.png'其中Image = null

解决方案

尝试下面

 更新 
Info
SET
image = ' Image / defalt.png'
WHERE
图片 IS NULL





Quote:

我们如何测试NULL值?



< b>无法使用比较运算符测试NULL值,例如=,<或<> ;.



W e必须使用 IS NULL IS NOT NULL 运算符。

参考 [ ^ ]


严格说:不可能使用比较运算符,例如:< > =

看看这里: NULL比较搜索条件 [ ^ ]



使用比较运算符 NULL ,使用 COALESCE [ ^ ]函数,用于评估NULL值呃。

样本1

  SELECT  IntField 
FROM TableName
WHERE COALESCE (IntField , 0 )= 0



样本2

  SELECT  StringField 
FROM TableName
WHERE COALESCE (StringField,' ')= ' '


I am trying to update image column with A string where Its Is NULL Now..But
Its not working...My Query Below..
Any One Can Explain me why Its Happens..

update Info set image='Image/defalt.png' where Image=null

解决方案

try below

UPDATE
      Info 
SET
    image='Image/defalt.png' 
WHERE
   Image IS NULL



Quote:

How can we test for NULL values?

It is not possible to test for NULL values with comparison operators, such as =, <, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.

Reference[^]


Strictly saying: it's impossible to use comparison operators, like: <, > or =.
Have a look here: NULL Comparison Search Conditions[^]

To use comparison operators with NULL, use COALESCE[^] function, which evaluates NULL values with other.
Sample 1

SELECT IntField
FROM TableName
WHERE COALESCE(IntField, 0) = 0


Sample 2

SELECT StringField
FROM TableName
WHERE COALESCE(StringField, '') = ''


这篇关于更新Sql Server中的Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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