all groups > sql server new users > june 2007 >
You're in the

sql server new users

group:

Rows to Columns



Rows to Columns WANNABE
6/16/2007 9:25:29 PM
sql server new users: How can I convert the results of this query
SELECT num1, COUNT(num1) Total
FROM tbl
GROUP BY num1
Which displays like this
Adult 2
Minor 2
BUT I WANT IT TO DISPLAY LIKE
Adult Minor
2 2

Can this be done and how?? I've looked at the new PIVOT, and I am using 2005,
but I don't understand what I've read and there's not much I can find to read.
Thanks.

Re: Rows to Columns Tom Moreau
6/17/2007 11:59:34 AM
This will work in both SQL 2000 and SQL 2005:

select
sum (case when num1 = 'Adult' then 1 else 0 end) Adult
, sum (case when num1 = 'Minor' then 1 else 0 end) Minor
from
tbl

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


[quoted text, click to view]
How can I convert the results of this query
SELECT num1, COUNT(num1) Total
FROM tbl
GROUP BY num1
Which displays like this
Adult 2
Minor 2
BUT I WANT IT TO DISPLAY LIKE
Adult Minor
2 2

Can this be done and how?? I've looked at the new PIVOT, and I am using
2005,
but I don't understand what I've read and there's not much I can find to
read.
Thanks.

Re: Rows to Columns WANNABE
6/17/2007 9:42:35 PM
Thanks allot Tom, That works GREAT!!!
==============================
[quoted text, click to view]
This will work in both SQL 2000 and SQL 2005:

select
sum (case when num1 = 'Adult' then 1 else 0 end) Adult
, sum (case when num1 = 'Minor' then 1 else 0 end) Minor
from
tbl

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


[quoted text, click to view]
How can I convert the results of this query
SELECT num1, COUNT(num1) Total
FROM tbl
GROUP BY num1
Which displays like this
Adult 2
Minor 2
BUT I WANT IT TO DISPLAY LIKE
Adult Minor
2 2

Can this be done and how?? I've looked at the new PIVOT, and I am using
2005,
but I don't understand what I've read and there's not much I can find to
read.
Thanks.


AddThis Social Bookmark Button