melegant99
asked on
Case Statement SQL
I want to check a parameter's length of text with a case statement, what is wrong with this?
CASE @pname WHEN (dbo.length(@pname) > 0) THEN ('arc.contact_name LIKE ''' + @pname + '%'' AND ') ELSE '' END
getting an error about the >
Incorrect syntax near '>'.
Thanks.
CASE @pname WHEN (dbo.length(@pname) > 0) THEN ('arc.contact_name LIKE ''' + @pname + '%'' AND ') ELSE '' END
getting an error about the >
Incorrect syntax near '>'.
Thanks.
No need of dbo.length instead use Len((@pname)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also go this way:
IF(Len(@pname) > 0)
select 'arc.contact_name LIKE ''' + @pname + '%'' AND '
ELSE
select ''
IF(Len(@pname) > 0)
select 'arc.contact_name LIKE ''' + @pname + '%'' AND '
ELSE
select ''