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 |
|
ceema
Yak Posting Veteran
80 Posts |
Posted - 2006-12-07 : 20:54:34
|
| Hello all,I have a table "News" with the following fields, I want to get the result according to categoryidNewsID numeric 9CategoryID smallintTitle nvarchar(100)For example It's values areNewsID CategoryID Title--------------------------1 3 All are well2 1 No Rain Today3 1 Heavy rain today4 2 New flowersso, I should get title with categoryid 1 as weather,2 as nature,3 as lifeI triedselect (select Title from News where CategoryID=1) as weather,(select Title from News where CategoryID=2) as nature,(select Title from News where CategoryID=3) as life from News, but as you can imagine, it's not workingThanksCeema |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-12-08 : 02:13:14
|
| [code]SELECT CASE WHEN CategoryID = 1 THEN Title END AS Weather, CASE WHEN CategoryID = 2 THEN Title END AS Nature, CASE WHEN CategoryID = 3 THEN Title END AS LifeFROM News[/code]-- If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime. |
 |
|
|
ceema
Yak Posting Veteran
80 Posts |
Posted - 2006-12-08 : 02:22:26
|
| PSamsig, Thank you so much. It's working fine.RegardsCeema |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-08 : 02:45:47
|
| Read about Cross-tab Reports from more informationsMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|