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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query

Author  Topic 

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-05-08 : 05:07:29
Hi

i have a sql Statment which has the following Result set

Stats Statname
---- ------
54 Members
585 PRESENTATION
1083 VIEWS
1138 VIEWlOGS

i Want this in a single Row as follows

Members PRESENTATION VIEWS VIEWlOGS
------- ----------- ---- ---------
54 585 1083 1183


How can i design a query for this

Please help

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-05-08 : 05:14:45
declare @tt table (Stats int, Statname varchar(30))
insert @tt
select 54, 'Members' union
select 585, 'PRESENTATION' union
select 1083, 'VIEWS' union
select 1138, 'VIEWlOGS'

Select
Max(Case when Statname = 'Members' then Stats end) as Members,
max(Case when Statname = 'PRESENTATION' then Stats end) as PRESENTATION,
Max(Case when Statname = 'VIEWS' then Stats end) as VIEWS,
Max(Case when Statname = 'VIEWlOGS' then Stats end) as VIEWlOGS from @tt
Go to Top of Page

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-05-08 : 05:28:07
Thanks dear, it worked
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-08 : 10:28:29
Also read about Cross-tab reports in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -