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)
 Cross tabs

Author  Topic 

Trevor
Starting Member

6 Posts

Posted - 2005-10-20 : 10:24:07
I am fairly new to sql and have never used cross tabs. I have list a charities that receive 2 to 3 flats of mail a day. I need a report that shows how many come in for each one by date, but the problem is totaling for each charity by week. similar to whats below.


DATE Total Charity Charity Charity Charity Charity Charity Charity Charity Charity Charity Charity Charity
1/31 40.25 11.5 7.25 7.5 0.5 7.25 2 4.25
2/1 8.75 3 1 1.5 0.75 0.75 0.25 1.5
2/2 8.75 3.25 1.5 1.25 0.25 1 0.5 1
2/3 17.50 3.5 7 2 1 1.5 0.75 1.75
2/4 18.75 7 4 2 1.5 1.25 1 2
week 94.00 0.00 28.25 20.75 14.25 4.00 11.75 4.50 10.50 0.00 0.00 0.00 0.00 0.00
2/7 41.75 12 10 3.5 7 2 3.5 3.75
2/8 6.00 1.25 1 0.5 1 0.5 1.25 0.5
2/9 7.25 1 2 0.5 1.5 0.75 1.5 0
2/10 15.25 2 4.25 1 2 1.5 4 0.5
2/11 16.00 1.5 5.75 1 1.75 0.5 5 0.5


I can get it to display each daily amount for the charity, but have no idea to total by week. Can anyone point me in the right direction.
Here is what I have to far. Any help would be greatly appreciated.

ALTER PROC usp_DAILY
AS
select
[date],
COUNT(case when okey = 1 then completed else null end) as CH1,
count(case when okey = 2 then completed else null end) as CH2,
count(case when okey = 3 then completed else null end) as CH3,
count(case when okey = 4 then completed else null end) as CH4,
count(case when okey = 5 then completed else null end) as CH5,
count(case when okey = 6 then completed else null end) as CH6,
count(case when okey = 7 then completed else null end) as CH7,
count(case when okey = 8 then completed else null end) as CH8,
count(case when okey = 9 then completed else null end) as CH9,
count(case when okey = 11 then completed else null end) as CH10,
count(case when okey = 12 then completed else null end) as CH11,
count(case when okey = 13 then completed else null end) as CH12,
count(case when okey = 14 then completed else null end) as CH13,
count(case when okey = 15 then completed else null end) as CH14,
count(*) as Total

from
CagingTransactions
group by
[date]


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-20 : 10:27:12
See if this helps you
http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

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

- Advertisement -