Reputation: 1021
If I don't want to treat an empty string and NULL as being the same value, is there a cleaner way to write the following:
-- @name and SomeTable.Name are varchar(10) NULL
update SomeTable set Name = @name
where
Id = 5
and (
Name != @name
or name is null and @name is not null
or name is not null and @name is null)
)
It seems dirty to use a value that I think should not be valid:
isnull(Name, '!invalid!') != isnull(@name, '!invalid!')
So if @name is NULL and column Name is not, or vice versa, or if they both have a value which is not the same, I want the update to happen.
Upvotes: 0
Views: 69