Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flatten results 1

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
I have the following query which counts the instances of a certain field. This works just fine however it returns the results on 3 lines and what I need it to do it return this on just one line:

Code:
select	ofr.officername,
	sum(case PCRatingID
		when 1 then 1 else 0
	end) as 'Excellent',
	sum(case PCRatingID
		when 2 then 1 else 0
	end) as 'Satisfactory',
	sum(case PCRatingID
		when 3 then 1 else 0
	end) as 'Unsatifactory'
		
from	CustomerBaseMain cbm left join officers ofr
		on cbm.officerid = ofr.officerid 
	inner join Plausibility pl
		on cbm.AccountID = pl.AccountID
where	cbm.actiondate between '01SEP2006' and '12APR2007'
and 	cbm.officerid in ('123456','654321','123654')
Group By ofr.officername, PCRatingID

All input appreciated!

Thanks
 
here you go, output on just one line --
Code:
select sum(case PCRatingID
           when 1 then 1 else 0 end) as 'Excellent'
     , sum(case PCRatingID
           when 2 then 1 else 0 end) as 'Satisfactory'
     , sum(case PCRatingID
           when 3 then 1 else 0 end) as 'Unsatifactory'
  from CustomerBaseMain cbm 
inner 
  join Plausibility pl
    on pl.AccountID = cbm.AccountID
left 
  join officers ofr
    on ofr.officerid = cbm.officerid 
 where cbm.actiondate 
       between '01SEP2006' and '12APR2007'
   and cbm.officerid 
       in ('123456','654321','123654')

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top