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 |
|
joelseverich
Starting Member
34 Posts |
Posted - 2010-04-26 : 11:10:13
|
| Hi.I have a table with columns (code, name, cost, type)type can be 'A' or 'B', now how can i select cost as costA when type is 'A' and costB when type is 'B'please help me on this. |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-04-26 : 11:15:15
|
| SELECTCode,Name,Type,CASE WHEN Type = 'A' THEN cost ELSE 0 END AS CostA,CASE WHEN Type = 'B' THEN cost ELSE 0 END AS CostBFROM Table |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-26 : 11:16:40
|
| [code]SELECT code, name, CASE WHEN Type = 'A' THEN cost ELSE NULL END AS CostA, CASE WHEN Type = 'B' THEN cost ELSE NULL END AS CostBFROM tableName[/code]------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
joelseverich
Starting Member
34 Posts |
Posted - 2010-04-26 : 11:22:30
|
| it worked perfectly, thanks a lot |
 |
|
|
|
|
|