I have a query, in this there are multiple conditions based on parameter
select a,b,c,d from xyz where
case p='Closed' then (q-r)=0
case p='Pending' then (q - isnull(r,0) )>0
case P='All' then all records to be display
It gives Incorrect Syntax near line case
Kindly suggest me any other solution to change 'where condition' depending on parameter value,
since in given sql, 'where' condition is depend on parameter p value.
You can see in given syntax, if the parameter value is change, condition also get changed.
In first case if p='Closed' then select ... where q-isnull(r,0)=0
if p='Pending' then select ... where (q - isnull(r,0) )>0
In first condition it is comparing 'equal to' condition & in next example it is 'greater than' zero value.
like in third condition I want to display all records.
Here problem is, 'case' structure is only return a value, not expression.
Requested for one complete query for all above criteria
– curious K Nov 08 '17 at 13:37