Skip to content
Advertisement

How to replace empty spaces with NULL

I have a column in sql server 2012 which contain white spaces. I want to replace these empty spaces with NULL. I have written the following query but its not working.

SELECT replace(COLUMN1, '',NULL) 
FROM Orders;

How to achieve the above functionality. Thanks in advance.

Advertisement

Answer

Use nullif

select nullif(Column1, '') from Orders
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement