How to write IsNullOrEmpty method similar to ISNULL in sql server

vishal picture vishal · Aug 19, 2015 · Viewed 10.9k times · Source

I want to have function in sql server similar to ISNULL() except it should check expression for null and empty also.

If first parameter is null or empty, returns second.

can someone help me?

Answer

Tim Schmelter picture Tim Schmelter · Aug 19, 2015

You can use NULLIF and ISNULL:

SELECT ISNULL(NULLIF(@parameter, ''), @parameter2)