Replace empty record in ms sql server

Couple of days ago while working in a project I got requirement to replace empty or we say blank record with space. Remember I am asking to replace the record that doesn’t exist with space, means it’s not related to NULL data, not related to space in column etc.
One more thing which was very strange for me at that time and I want to add it here that you can replace empty record with space by using different possible ways but to retrieve space in front end (Website) most of them doesn’t work and you may surprise that in ms sql server it is returning space but why let's suppose asp.net code is unable to get that space. So the methods work fine for me are listed below
SELECT ISNULL(NULLIF(DATABASE_COLUMN,''),' ')
SELECT ISNULL(DATABASE_COLUMN,' ')
NULLIF returns the first expression if the two expressions are not equal. If the expressions are equal, NULLIF returns a null value of the type of the first expression and if first expression is empty/blank then NULLIF returns a null value of the type of the first expression.

So that’s it. Enjoy your life.

0 comments: