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:
please use case command.case structure is:
case when condition then 'some value' else 'some other value' end
some example:
declare @SomeVarcharParm as nvarchar(20)=''
declare @SomeVarcharParm2 as nvarchar(20)=''
--select 1 or 2
select case when @SomeVarcharParm is null or @SomeVarcharParm='' then 1 else 2 end
--if null or empty set 'empty' value else set @SomeVarcharParm value
select @SomeVarcharParm2=case when @SomeVarcharParm is null or @SomeVarcharParm='' then 'empty' else @SomeVarcharParm end
--use null or empty in update command
update tbl1
set field1=case when field1 is null or field1='' then @SomeVarcharParm2 else field1 end
where id=1