CASE function

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 2
Reputation: marcel1 is an unknown quantity at this point 
Solved Threads: 0
marcel1 marcel1 is offline Offline
Newbie Poster

CASE function

 
0
  #1
Jun 4th, 2008
Please, try to help with this. I use case statement but for 2 arguments.
Down here is the idea of what i want to get:

select x case x
when x = 'AB' and y like 'CD%' then x= 'CD'
when x = 'ZZ' and y like 'CC%' then x= 'BA'
when x in ('bbb','sss','ddg') then x= 'BB'

I ll be grateful if anyone would help write right querry.
Thank in advance
Marcel
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: CASE function

 
0
  #2
Jun 4th, 2008
hi marcel1,
below select with case clause is standard SQL1999. Maybe it works also on MS SQL Server.
  1. SELECT x,
  2. (
  3. CASE
  4. WHEN x = 'AB' AND y LIKE 'CD%' THEN 'CD'
  5. WHEN 'ZZ' AND y LIKE 'CC%' THEN 'BA'
  6. WHEN x IN ('bbb','sss','ddg') THEN 'BB'
  7. ELSE 'unknown thing'
  8. END
  9. ) AS xx
  10. FROM yourtable WHERE ... ;
  1. This will produce a list WITH two COLUMNS, FOR example
  2. x xx
  3. ------------
  4. AB CD
  5. sss BB
  6. wow unknown thing
You can also omit the first attribute x from the select, if you don't need original x values.
Like x, y must also be attribute of yourTable.

Maybe this will help you.

krs,
tesu
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 2
Reputation: marcel1 is an unknown quantity at this point 
Solved Threads: 0
marcel1 marcel1 is offline Offline
Newbie Poster

Re: CASE function

 
0
  #3
Jun 5th, 2008
That works just fine.
Thanks
Marcel
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC