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:
Use this function (based on Derek's):
CREATE FUNCTION dbo.isNullOrEmpty(@x varchar(max)) RETURNS BIT AS BEGIN IF @x IS NOT NULL AND LEN(@x) > 0 RETURN 0 RETURN 1 END
as
dbo.isNullOrEmpty(@someVar)
or
WHERE dbo.isNullOrEmpty(@someVar) = 1
in a stored procedure or query.