Muf*_*lix 7 sql sql-server-2008-r2
I discover some behavior I didn't know before. Why this line of code does not work?
SELECT REPLACE('','','0') ==> returns ''
Run Code Online (Sandbox Code Playgroud)
I can't even have '' in where condition. It just doesn't work. I have this from imported Excel where in some cells are no values but I'm not able to remove them unless I used LEN('') = 0 function.
Tim*_*ter 14
There is nothing to replace in an empty string. REPLACE replaces a sequence of characters in a string with another set of characters.
You could use NULLIF to treat it as NULL + COALESCE (or ISNULL):
declare @value varchar(10);
set @value = '';
SELECT COALESCE(NULLIF(@value,''), '0')
Run Code Online (Sandbox Code Playgroud)
This returns '0'.