October 22, 2010 at 5:16 am
Hello there
I have this query:
select [PCode], Count([PCode]) as PNum
from [dbo].P_Staging
group by [PCode]
this displays:
PcodePNum
5F5233971
5F7298505
5HG315766
5HP153086
How do I go about returning a result where the rows are the columns e.g:
5F5,5F7,5HG,5HP
233971,298505,315766,153086
Do i have to use a pivot for this, or is there a simpler way?
Andy
October 22, 2010 at 5:33 am
You can use either PIVOT or CROSS TABS. CROSS TABS according to me are easier to understand.
The links below contain good articles on the same
http://www.sqlservercentral.com/articles/T-SQL/63681/
http://www.sqlservercentral.com/articles/Crosstab/65048/
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
October 25, 2010 at 3:17 am
Thank you, I have this working
It just sounds like it should be much easier to do than it is.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply