April 12, 2012 at 2:18 pm
Doing crosstabulation with the PIVOT operator would be very helpful for me, but this simple query returns an odd error.
------------------------------------
Select occurrence_post, z
from
(
SELECT occurrence_post, 1 as z
FROM tblPostOpOccurrences
) as s
PIVOT
(
SUM(z)
FOR occurrence_post IN ([31],[27])
)
as p
-------------------------------------
SQL Server 2005 management studio returns this error when I run the query
Msg 207, Level 16, State 1, Line 1
Invalid column name 'occurrence_post'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'z'.
Why are occurrence_post and z invalid columns??
Any help with getting PIVOT to work would be a great help
thanks !
phunhog
April 12, 2012 at 2:26 pm
It should be
Select [31] , [27]
from
(
SELECT occurrence_post, 1 as z
FROM tblPostOpOccurrences
) as s
PIVOT
(
SUM(z)
FOR occurrence_post IN ([31],[27])
)
as p
April 12, 2012 at 2:37 pm
Right you are ColdCoffee
I should have asked sooner
thank you!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply