SELECT MULTIPLE VALUES IN WHERE CLAUSE BASED ON THE VALUE PASSED AS INPUT PARAMETER
-
10 июня 2012 г. 18:37
I want to select multiple values from the database when I am passing a specific input parameter value to my stored procedure . How to do that ?
Currently this is what I am doing..
WHERE
zDescription like '%WebQuote%'
and
(ExpectedCloseDate>=@startDateExClose and ExpectedCloseDate-1<@endDate)
and
Status like
CASE WHEN @status = 'SPA Pending' then Status IN('Active','SPA Pending')
else
@status endAND
SO ON
So when the input parameter is SPA Pending I want to select the status as both Active and SPA Pending and otherwise I want to select the Status as the exact value passed through the parameter for Status. Can anyone help me on this ?
Thanks in advance.
Regards,
Vivek
Vivek Kamath
- Изменено Vivek Kamath 10 июня 2012 г. 20:09
Все ответы
-
10 июня 2012 г. 19:11
(
(@status = 'SPA Pending' and Status IN('Active','SPA Pending'))
OR(@status = Status)
)
- Изменено Piotr Palka 10 июня 2012 г. 19:11
-
10 июня 2012 г. 19:24
Hello Piotr,
I used the above code and tried . Syntax wise it worked but it's not returning me any values that I needed.
I am passing the parameters like this
cmd.Parameters.Add("@status",status+'%');
Previously when I was not having a case like this in the WHERE clause I was using a statement like this:
WHERE Status like @status
Can I get the solution specific to my case ?
Vivek Kamath
-
10 июня 2012 г. 19:31
Try following:
(
(@status = 'SPA Pending' and Status IN('Active','SPA Pending'))
OR (Status like @status)
)
-
10 июня 2012 г. 19:34
Or maybe few more changes:
( (@status = 'SPA Pending%' and (Status like 'Active%' or Status like 'SPA Pending%')) OR (Status like @status) )
- Помечено в качестве ответа Vivek Kamath 10 июня 2012 г. 19:48
-
10 июня 2012 г. 19:35I tried the same before part of it works but it fails in case of when @status = 'SPA Pending'
Vivek Kamath
-
10 июня 2012 г. 19:50This worked. Thanks a lot Piotr. Was stuck at this thing for a long time. Highly Appreciate you for your help.
Vivek Kamath

