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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frogman22Author Commented:
Works Excellent!!!!!!!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.