Brad Hines
Brad Hines

Reputation: 107

Access SQL With PIVOT

I'm using Access and attempting to duplicate some syntax I found on MSDN. Unfortunately it seems Access is having a problem with a FROM statement in my Syntax. I'm not sure why.

SELECT YEAR, HC
FROM
(
SELECT [Retention & Graduation].Year, [Retention & Graduation].Status, [Retention & Graduation].Hc
FROM [Retention & Graduation]
) AS X

PIVOT
(
SUM([HC]) FOR [STATUS] IN ([GONE], [HERE], [GRAD])
) AS Xx

Upvotes: 1

Views: 8893

Answers (1)

Taryn
Taryn

Reputation: 247670

The syntax to pivot in MS Access is different from sql server. You have to use the TRANSFORM function to pivot data.

The syntax will be similar to this:

TRANSFORM SUM([Retention & Graduation].Hc)
SELECT [Retention & Graduation].Year, 
  [Retention & Graduation].Status, 
  [Retention & Graduation].Hc
FROM [Retention & Graduation]
GROUP BY [Retention & Graduation].Year
PIVOT [Retention & Graduation].[STATUS]

Upvotes: 7

Related Questions