Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Multiple Counts in a Row Expand / Collapse
Author
Message
Posted Tuesday, October 9, 2007 11:46 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, May 1, 2013 8:10 AM
Points: 445, Visits: 840
As everyone else has said formatting is best left to reporting tools but this will do what you want.


declare @delim1 varchar(30),@delim2 varchar(30),@delim3 varchar(30)

select @delim1 = '---------------'+ char(10) + char(13)
select @delim2 = char(10) + char(13)
select @delim3 = ','
select @delim1,facility,@delim2,sum(case when something = somethingelse then 1 else 0 end) as con1,@delim3,sum(case when something = somethingelse then 1 else 0 end) as con2,@delim3,sum(case when something = somethingelse then 1 else 0 end) as con3,@delim2,@delim1 from #temp
group by facility







Post #408616
Posted Thursday, October 14, 2010 9:50 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, March 25, 2011 11:46 AM
Points: 15, Visits: 49
ALZDBA's solution works perfectly... (atleast for me)

select Facility,
sum(case when condition_1 then 1 else 0 end),
sum(case when condition2 then 1 else 0 end)
from Table
group by Facility

Solution would look like this:

Facility_1 Count(for_condition_1) Count(for_condition_2) ......
Post #1004525
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse