Hello,
I'm trying to set up a where clause with (among other things) a selection of a variable if it has a value other than "all" or a wildcard if it is "all." I'm pulling the data from a temp table.
I'm not sure how to code this and have botched it in several different ways. Can you help me? (beginner here). Here are the error messages and code below that:
Here's what I have now that isn't working:
I'm trying to set up a where clause with (among other things) a selection of a variable if it has a value other than "all" or a wildcard if it is "all." I'm pulling the data from a temp table.
I'm not sure how to code this and have botched it in several different ways. Can you help me? (beginner here). Here are the error messages and code below that:
Code:
Server: Msg 156, Level 15, State 1, Procedure usp_ProgressNotes, Line 186
Incorrect syntax near the keyword 'if'.
Server: Msg 156, Level 15, State 1, Procedure usp_ProgressNotes, Line 186
Incorrect syntax near the keyword 'THEN'.
Server: Msg 156, Level 15, State 1, Procedure usp_ProgressNotes, Line 188
Incorrect syntax near the keyword 'then'.
Here's what I have now that isn't working:
Code:
Select top 10* from #TmpProgressNotes WHERE
if @ServiceCodeGroup LIKE 'All Service Codes' THEN
ServiceCodeGrpDesc LIKE '%'
else if not ISNULL(@ServiceCodeGroup,'NULL') then
ServiceCodeGrpDesc=@ServiceCodeGroup
end