Hi all,
I have an accident database that I am trying to write a pivot query for.
the following works:
TRANSFORM Nz(Count([I_BA]),0) AS [The Value]
SELECT TblMonthlyInjurySummary.I_BA
FROM TblMonthlyInjurySummary
WHERE ((TblMonthlyInjurySummary.I_Date) Between #7/1/2000# And #6/30/2011#)
GROUP BY TblMonthlyInjurySummary.I_BA
PIVOT IIf([ReportMonth]<=7,Cstr([ReportYear]-1) & " to " & Cstr([Reportyear]),Cstr([ReportYear]) & " to " & Cstr([ReportYear]+1));
which gives the numbers down the left column and years accross the top.
The I_BA is a number for a breakdown agency (i.e. 1- hit by obect), ReportYear is the year it occurred in (which comes from the I_DAtE when it is entered), I_DAte is actuallu the date the incident occurred.
What I would like is the years down the left and the grouped BA across the top. (The above SQL works but I cant figure out how to rotate the table around.)
PS I am not very good at SQL especially Pivot tables (somebody else helped me with the above query)
Any ideas?
cheers
Tony
I have an accident database that I am trying to write a pivot query for.
the following works:
TRANSFORM Nz(Count([I_BA]),0) AS [The Value]
SELECT TblMonthlyInjurySummary.I_BA
FROM TblMonthlyInjurySummary
WHERE ((TblMonthlyInjurySummary.I_Date) Between #7/1/2000# And #6/30/2011#)
GROUP BY TblMonthlyInjurySummary.I_BA
PIVOT IIf([ReportMonth]<=7,Cstr([ReportYear]-1) & " to " & Cstr([Reportyear]),Cstr([ReportYear]) & " to " & Cstr([ReportYear]+1));
which gives the numbers down the left column and years accross the top.
The I_BA is a number for a breakdown agency (i.e. 1- hit by obect), ReportYear is the year it occurred in (which comes from the I_DAtE when it is entered), I_DAte is actuallu the date the incident occurred.
What I would like is the years down the left and the grouped BA across the top. (The above SQL works but I cant figure out how to rotate the table around.)
PS I am not very good at SQL especially Pivot tables (somebody else helped me with the above query)
Any ideas?
cheers
Tony