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:
IF @SomeVarcharParm IS NOT NULL AND LEN(@SomeVarcharParm) > 0
BEGIN
-- do stuff
END
There’s gotta be a better way to do this. Isn’t there?
You can do
ISNULL(@SomeVarcharParam, '') <> ''or you can create a UDF that returns a bit:And call that using
IF NOT dbo.IsNullOrEmpty(@SomeVarcharParam) BEGIN ...Keep in mind that when calling a UDF, you MUST prefix the owner of it (here, dbo.)