As the name has already been mentioned, I am struggling with my proposal WHEREin the SQL stored procedure.
I received a query SELECTthat connects well to several tables and at the end, if I received a sentence WHEREthat gives specific values for the search.
My problem is that I want to deploy this stored procedure for 2 different sentences WHERE, but I cannot get the right one IF ELSEto parse the request.
For instance:
SELECT .......
FROM TABLE_X
INNER JOIN TABLE_Y.....
WHERE
man.Klant_ID = @Klant
AND (@ManID = 0 OR man.ID = @ManID)
AND .... (which continues like the rule above)
Here I want to get something like this:
SELECT .......
FROM TABLE_X
INNER JOIN TABLE_Y.....
IF @TEMPVAR = ''
WHERE man.Klant_ID=@Klant
AND (@ManID = 0 OR man.ID = @ManID)
AND...
ELSE
WHERE TABLE_X.ID IN (@TEMPVAR)
(and @tempvarshould contain a comma separated identifier, like 10001,10002,10003)
I am struggling with the syntax and have been looking for some time, but cannot find the right solution.
Thanks in advance!