Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Replace null string with null value

Writer Matthew Barrera

I have a table that has a string value of 'null' that I wish to replace with an actual NULL value.

However if I try to do the following in my select

Select Replace(Mark,'null',NULL) from tblname

It replaces all rows and not just the rows with the string. If I change it to

Select Replace(Mark,'null',0) from tblname

It does what I would expect and only change the ones with string 'null'

3

1 Answer

You can use NULLIF:

SELECT NULLIF(Mark,'null')
FROM tblname;
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.