Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2012-11-06 : 09:07:35
|
Hello there.i have a sp with a parameter called @type.the @parameter will except either. 1,2 or 3i want a case that says 1 = First, 2 second. which is the easy bit.but when 3 is entered i want the case to include a couple of items.eg set @type = (select case @typeSelectionwhen '3' then 'first', 'second', 'third' else @typeSelection end)The result will end up in a where clause in another select statement iewhere selection in (@type )is there a way round this?RegardsRob |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-11-06 : 09:11:51
|
Put the case expression into the WHERE clause.where selection in (case @typeSelection when '3' then ' ''first'', ''second'', ''third'' ' else @typeSelection end) Too old to Rock'n'Roll too young to die. |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2012-11-06 : 09:15:38
|
Thank you |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-06 : 12:16:03
|
how will values be present n your table column selection? is it comma separated or individual values?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2012-11-07 : 04:01:48
|
i am using this for a search page in an asp.net website.so some fields are freetext and couple are drop down lists. |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2012-11-07 : 06:11:25
|
I am defining a variable as %% if the required parameter is null or ''how do i define a variable as %% but also with '' on the outside. eg '%%'is there a way i can do this. does the character ' have an ascii value i could use? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-07 : 09:21:55
|
quote: Originally posted by masterdineen I am defining a variable as %% if the required parameter is null or ''how do i define a variable as %% but also with '' on the outside. eg '%%'is there a way i can do this. does the character ' have an ascii value i could use?
you dont have to do that you can simply add a OR condition likeOR @param=''so that it bypasses filter when '' and gives you all the values------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|