Sampath Sampath - 5 months ago 14
SQL Question

Replace `0` instead of the `NULL` SQL

I need to replace

0
instead of the
NULL
value.I have tried as shown below.But it's not working.Can you tell me why ?


SELECT REPLACE(a.[BPOAGE], 'NULL', 0),a.[BPOAttic] FROM
[Legacy].[dbo].[MyTables] as a


Result :

enter image description here

Answer

NULL isn't the same as 'NULL' (one is the absence of a value, one is the string with letters N, U, L and L), so replacing it like that doesn't work.

Try using the ISNULL or COALESCE operators.

SELECT ISNULL(a.[BPOAGE], 0) AS BPOAGE
  , a.[BPOAttic] 
FROM [Legacy].[dbo].[MyTables] as a