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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case of a case

Author  Topic 

sqlnewbie87
Starting Member

4 Posts

Posted - 2011-06-21 : 07:35:08
hi there,

here is my problem. lets assume i have a followin table:

status test test2
------ ----- -----
1 5 25
2
3
1 5 25
1 5 25
1 5 25
2
1 5 25
1 5 25

I need to do two things first derive a case and the consequent column 2 via

select status,
case status
when '1' then status*5
else ''.
END AS test

select TEST,
case TEST
when '5' then status*5
else ''.
END AS test2

CAN U TELL ME WHO TO DERIVE A THIRD COLUMN FROM CASE AS WELL
MANY THANKS,
D

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-21 : 07:42:12
select status,
Test ,
case Test
when '5' then status*5
else ''.
END AS test2
from
(
select status,
case status
when '1' then status*5
else ''.
END AS test ,
from tbl
) a

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -