Niranjan Godbole Niranjan Godbole - 11 days ago 7
SQL Question

How to update table column in SQL Server only wherever null appears?

I have a SQL Server table with more than 15 columns.

One of my column name is

verification_Status
. Currently, I have
0, 1, 2, null
values under
verification_Status
as below:

For example:

Id Name verification_Status
1 John 0
2 Kat 1
3 Williams Null
4 Rosy null


I want to make 0 wherever null appears. I have 4k rows to update so I am little worried.

update masterTable
set verification_Status = 0
where verification_Status == null


I am planning to use above query.

May I know this is the right query to my problem? Can someone guide me on this?

Answer

Use this:

update masterTable 
set verification_Status = 0 
where verification_Status is null

<> is Standard SQL; != is its T-SQL equivalent. Both evaluate for values, which NULL is not -- NULL is a placeholder to say there is the absence of a value.

Which is why you can only use IS NULL / IS NOT NULL as predicates for such situations.

This is standard of all kinds of SQL management platforms