One approach:
(SQLSrv 2005 Compatibility level 90 required)
USE MyDB;
GOSELECT Code, [Jan] AS Jan_Val, [Feb] AS Feb_ValFROM (SELECT Code, Month,
ValueFROM MyTable) pPIVOT(MAX (Value)FOR Month IN( [Jan],[Feb] )) AS
pvtORDER BY CodeWHERE Year = 2006This assumes that your Month field contains
the values Jan, Feb, etc. Obviously, the above would need to be expanded to
accomodate additional months.
[quoted text, click to view] "R" <mymail@somemail.com> wrote in message
news:u9bEOZzOHHA.5064@TK2MSFTNGP04.phx.gbl...
>I need to create the equivalent to an Access crosstab query in SQL. Can
>someone help me with this? I'm new to SQL and need this report within the
>hour, unfortunately.
>
> The data table has four columns: Code, Value, Month, Year. There are 12
> records per Code representing each month of the year. (I will filter for
> the current year only.)
>
> I need to create a query/view that will show one record per Code, like
> this:
>
> Code Jan_Val Feb_Val Mar_Val Apr_Val etc.
>
> I'm very grateful for some quick help with this!
>
>
>