0

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

3
Contributors
3
Replies
5
Views
9 Years
Discussion Span
Last Post by teezecrost
0

hi marcel1,
below select with case clause is standard SQL1999. Maybe it works also on MS SQL Server.

SELECT x,  
(
  CASE
     WHEN x = 'AB' and y like 'CD%' then 'CD'
     WHEN 'ZZ' and y like 'CC%' then 'BA'
     WHEN x in ('bbb','sss','ddg') then 'BB' 
     ELSE 'unknown thing'
  END 
) AS xx
FROM yourtable where ... ;
This will produce a list with two columns, for example
x         xx
------------
AB       CD
sss       BB
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.