Changing a null string to an empty string in select statment

Look at the Coalesce function. It returns the first non null value passed in.

COALESCE( myValue , '' )

This will return myValue if it is not null, or an empty string (''), if it is.

It is less verbose than using many ISNULL() and IF clauses and as such can be easier to read.


Check out ISNULL() in the SQL Server Books Online.

Syntax:

ISNULL ( check_expression , replacement_value )

Example:

Select ISNULL(myfield1,'') from mytable1

Tags:

Sql Server