Hi again, probably a dumb question but here goes,
I'm doing a fairly simple query which uses a like operator in a where clause, kind of like the following:
WHERE Available LIKE 'O/L%'
But I'd like to be able to alter the caluse depending on the value of a parameter passed in, so I could change the clause to either LIKE ot NOT LIKE <value%>
I tried this but it didn't work:
WHERE Available @Parameter1 LIKE 'O/L%'
and I passed in either 'NOT' or ' as @Parameter1.
So I was wondering if there is a way of using an if - then statement in the Where clause that I could use to do something like this:
IF @Parameter1 = 'LIKE' THEN
WHERE Available LIKE 'O/L%'
ELSE
WHERE Available NOT LIKE 'O/L%'
END IF
I'm thinking this probably won't work either and that the answer is going to be Dynamic SQL (Which I have NO idea yet how to do). But any suggestions to help with a solution would be nice.
Thanks
Craig
Amesville
I'm doing a fairly simple query which uses a like operator in a where clause, kind of like the following:
WHERE Available LIKE 'O/L%'
But I'd like to be able to alter the caluse depending on the value of a parameter passed in, so I could change the clause to either LIKE ot NOT LIKE <value%>
I tried this but it didn't work:
WHERE Available @Parameter1 LIKE 'O/L%'
and I passed in either 'NOT' or ' as @Parameter1.
So I was wondering if there is a way of using an if - then statement in the Where clause that I could use to do something like this:
IF @Parameter1 = 'LIKE' THEN
WHERE Available LIKE 'O/L%'
ELSE
WHERE Available NOT LIKE 'O/L%'
END IF
I'm thinking this probably won't work either and that the answer is going to be Dynamic SQL (Which I have NO idea yet how to do). But any suggestions to help with a solution would be nice.
Thanks
Craig
Amesville