Hi!
I'm pretty new to tsql programming and was wondering if the following is possible with a CASE statement.
Depending on the parameters sent to a SP I want to retrieve different product codes. The tidiest way to do would be have a statement like:-
WHERE [Product].Type IN
CASE
WHEN @ExcInvDeposit = 1 THEN (124,344,549)
WHEN @ExcInvDeposit = 0 THEN (124,344)
END
Unfortunately this doesnt work and gives a syntax error. Does anyone know how i can combine a set of IN values with a CASE statement?
I have done various testing and following works:-
WHERE [Product].Type =
CASE
WHEN @ExcInvDeposit = 1 THEN 549
WHEN @ExcInvDeposit = 0 THEN 124
END
This suggests it is combining the IN clause that is causing the problem.
Any help would be much appreciated,
Thanks
229257
I'm pretty new to tsql programming and was wondering if the following is possible with a CASE statement.
Depending on the parameters sent to a SP I want to retrieve different product codes. The tidiest way to do would be have a statement like:-
WHERE [Product].Type IN
CASE
WHEN @ExcInvDeposit = 1 THEN (124,344,549)
WHEN @ExcInvDeposit = 0 THEN (124,344)
END
Unfortunately this doesnt work and gives a syntax error. Does anyone know how i can combine a set of IN values with a CASE statement?
I have done various testing and following works:-
WHERE [Product].Type =
CASE
WHEN @ExcInvDeposit = 1 THEN 549
WHEN @ExcInvDeposit = 0 THEN 124
END
This suggests it is combining the IN clause that is causing the problem.
Any help would be much appreciated,
Thanks
229257