SQL server case statement??
I'm trying to pass an operator(>,<,=) and numeric text box value to a SQL stored procedure. I would like to know the proper syntax for the following SQL case statment. I want to use each operator as a case. for example, if the operator is >, then select values from a column where the values are greater tha the textbox variable. if the operator is <, then select values from a column that are less than the textbox value.
Re: SQL server case statement??
Give this a try:
Code:
SELECT .....
WHERE
CASE
WHEN @operator = '>' AND Field > @TxtBoxVal THEN 1
WHEN @operator = '<' AND Field < @TxtBoxVal THEN 1
WHEN @operator = '=' AND Field = @TxtBoxVal THEN 1
ELSE 0
END = 1
It's a bit on the creative side,.... but I've done that kind of stuff before and it works... hopefully it's what you need.
-tg