Say I\'ve got a function or stored procedure that takes in several VARCHAR parameters. I\'ve gotten tired of writing SQL like this to test if these parameters have a value:
I realize this is an old question, but this is what I use in MSSQL:
LEN(ISNULL(@asdf, ''))>0
Example:
DECLARE @asdf varchar(10)
SET @asdf = NULL --You can change this value to test different outputs
BEGIN IF LEN(ISNULL(@asdf, '')) > 0
PRINT @asdf
ELSE
PRINT 'IS NullOrEmpty'
END
--You can use it inline like this:
PRINT CASE LEN(ISNULL(@asdf, '')) WHEN 0 THEN 'IS NullOrEmpty' ELSE @asdf END
I think this is simpler and more straight forward than the other solutions because it is literally checking if the string is null or has a length of 0.