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 2005 Forums
 Transact-SQL (2005)
 Query

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-03-25 : 14:44:24
Below is my query which provides the output..Is there any best best way to get the output instead of below query since it's been old fashion..

I want to generate a cross tab report..

select top 1 'a_school',
(select count(*) from vw_a_school where schoolName is not null) schoolName,
(select count(*) from vw_a_school where AVCode is not null) AVCode
from vw_a_school

Thanks for your help in advance !

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-25 : 14:51:48
[code]select top 1 'a_school',
count(case when schoolName is not null then 1 else null end) over () as schoolName,
count(case when AVCode is not null then 1 else null end) over () as AVCode
from vw_a_school
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-03-25 : 15:11:38
Thanks a lot for your response..

How can we write the same query with PIVOT Operator in SQL 2005

Thanks for your help in advance
Go to Top of Page
   

- Advertisement -