noober
noober

Reputation: 4938

NULL comparison

There is a query:

UPDATE MyTable SET nvarchar1 = 'blahblah'
WHERE Id = '096fe792-7313-416f-b3c8-327f46be73b6' AND nvarchar1 <> 'blablah'

It doesn't work, when nvarchar1 is NULL. How should I change it to make it work?

  1. It is important to me don't execute update, if value has not been really changed.
  2. I don't know column type. It can be not only nvarchar, but ntext, integer or float-point number as well.

Regards,

Upvotes: 2

Views: 129

Answers (2)

GSerg
GSerg

Reputation: 78210

UPDATE MyTable SET nvarchar1 = 'blahblah'
WHERE Id = '096fe792-7313-416f-b3c8-327f46be73b6' AND isnull(nvarchar1,'') <> 'blablah'

Upvotes: 0

JanW
JanW

Reputation: 1849

UPDATE MyTable SET nvarchar1 = 'blahblah'
WHERE Id = '096fe792-7313-416f-b3c8-327f46be73b6' 
AND (nvarchar1 IS NULL 
OR nvarchar1 <> 'blablah')

Do you mean this?

Upvotes: 2

Related Questions