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
 Transact-SQL (2000)
 Please Help To Display Months Score

Author  Topic 

muzaffar_ali99
Starting Member

33 Posts

Posted - 2007-04-26 : 04:42:32
I have a table in earned points,total points and Date is residing, The problem is i want to calculate percentage but displaying data in months for example

Tbl_Score
ScoreId Earned_Points Total_Points Points_Date
1 2 5 04/26/2007
2 3 10 05/05/2007
3 10 10 06/07/2007

Now My Desired result is


Score Jan Feb Mar April May June July Aug Sep Oct Nov Dec
40% 0% 0% 0% 40% 3% 100% 0% 0% 0% 0% 0% 0%

Means i want to show a trending report on the basis of score in Months Columns and also on give year mean data of 2006 or 2007 etc

Regards
Muzaffar Ali

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-26 : 04:45:24
select datepart(year, points_date),
sum(case when datepart(month, points_date) = 1 then 1 ELSE 0 end) as 'January',
sum(case when datepart(month, points_date) = 2 then 1 ELSE 0 end) as 'February',
...
from tbl_score
group by datepart(year, points_date)
order by datepart(year, points_date)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

muzaffar_ali99
Starting Member

33 Posts

Posted - 2007-04-26 : 05:28:12
Thanks that works great.
Go to Top of Page
   

- Advertisement -