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
 Old Forums
 CLOSED - General SQL Server
 result in format uregent please

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 below

select * from #Temp_Example4
INSERT 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.Cyear



RCount RMonth RYear vercount Ccount statusid
1 2 2004 NULL NULL NULL
1 1 2005 NULL NULL NULL
4 5 2005 NULL NULL NULL
52 8 2005 4 1 2
52 8 2005 4 3 3
52 9 2005 14 10 2
52 9 2005 14 2 3
52 9 2005 14 2 4
9 10 2005 3 2 2
1 11 2005 1 NULL NULL


here 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 CO
1 2 2004 NULL NULL Null Null
1 1 2005 NULL NULL Null Null
4 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 Null
1 11 2005 1 Null NULL Null

can any one help me please...


Regards,
Krishna Murthy


Mamatha

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-19 : 08:34:37
Not too sure what you want but maybe
select 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
) a
group 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.
Go to Top of Page
   

- Advertisement -