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 |
Mamatha
Posting Yak Master
102 Posts |
Posted - 2005-11-19 : 02:11:52
|
Hi,I have query like this it is diplaying the result as like belowselect * from #Temp_Example4INSERT INTO #Temp_Example4 (RCount, RMonth,RYear,vercount,Ccount,statusid)select RCount, RMonth,RYear,vercount,Ccount,statusid from #Temp_Example3 left outer join #Temp_Example1 on #Temp_Example3.RMonth=#Temp_Example1.Cmonth and #Temp_Example3.RYear=#Temp_Example1.CyearRCount RMonth RYear vercount Ccount statusid1 2 2004 NULL NULL NULL1 1 2005 NULL NULL NULL4 5 2005 NULL NULL NULL52 8 2005 4 1 252 8 2005 4 3 352 9 2005 14 10 252 9 2005 14 2 352 9 2005 14 2 49 10 2005 3 2 21 11 2005 1 NULL NULLhere the statusid is displaying in row wise for example statusid=2 it is displaying in row wise i need a query like it has to disply in separte column here i have statusid=2,3 and 4 these three should be displayed in column format not in row format...required output RCount RMonth RYear vercount F FO CO1 2 2004 NULL NULL Null Null1 1 2005 NULL NULL Null Null4 5 2005 NULL NULL Null Null 52 8 2005 4 1 3 Null 52 9 2005 14 10 2 2 9 10 2005 3 2 Null Null1 11 2005 1 Null NULL Nullcan any one help me please...Regards,Krishna MurthyMamatha |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-11-19 : 08:34:37
|
Not too sure what you want but maybeselect RCount, RMonth, RYear, vercount, F = max(case when statusid = 2 then Ccount end) ,FO = max(case when statusid = 3 then Ccount end) ,CO = max(case when statusid = 4 then Ccount end)from(select RCount, RMonth,RYear,vercount,Ccount,statusid from #Temp_Example3 left outer join #Temp_Example1 on #Temp_Example3.RMonth=#Temp_Example1.Cmonth and #Temp_Example3.RYear=#Temp_Example1.Cyear) agroup by RCount, RMonth, RYear, vercount==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
|
|
|
|
|