Need to display query result horizantal instead of vertical

I am doing a COUNT of records by month from table using "datepart" in t-sql.  (SQL Server 2005)

Current Results Example: month     counter
                                             1             10
                                             2               3
                                             3              46..etc up to 12 months

I need a result that looks likethis instead if possible:  1          2          3.......etc
                                                                                    10         3         46    

I did research but could not seem to find the right solution.  All help is greatly appreciated.

 
frogman22Asked:
Who is Participating?
 
kenwagersCommented:
Try this - a bit brute force, but should give you what you need.  If you want the numerical month number as the title, change the word 'January' to '1' (the 1 must be in quotes).

In my code, the column 'ts' is time stamp, and the table test has that column.

select
sum(case when datepart(month,ts)= 1 then 1 else 0 end) as January,
sum(case when datepart(month,ts)= 2 then 1 else 0 end) as February,
sum(case when datepart(month,ts)= 3 then 1 else 0 end) as March,
sum(case when datepart(month,ts)= 4 then 1 else 0 end) as April,
sum(case when datepart(month,ts)= 5 then 1 else 0 end) as May,
sum(case when datepart(month,ts)= 6 then 1 else 0 end) as June,
sum(case when datepart(month,ts)= 7 then 1 else 0 end) as July,
sum(case when datepart(month,ts)= 8 then 1 else 0 end) as August,
sum(case when datepart(month,ts)= 9 then 1 else 0 end) as September,
sum(case when datepart(month,ts)= 10 then 1 else 0 end) as October,
sum(case when datepart(month,ts)= 11 then 1 else 0 end) as November,
sum(case when datepart(month,ts)= 12 then 1 else 0 end) as December
from
test
0
 
frogman22Author Commented:
Works Excellent!!!!!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.