- Aug 12, 2004
- 106
- 0
- 76
hello
I created a crosstab query that more or less works fine.
Due to how the databases i have to work with are set up, I have been trying to move some of my custom queries to access reports because it will automatically do a lot of the formatting and such that I would otherwise have to do manually with the query results over in word or excel.
In order to get a crosstab query to work in an access report, from what I understand I need to specify all column headings, at least that is what random googling and access error messages are telling me (note I am also trying to teach myself to do more and more of this in sql, because if I get my project approved, I get a real sql database for my emr records, as opposed to the situation I deal with now, anyway).
The table it pulls from LDExport
It uses the fields
PT-AGE
Method of Delivery Baby A
Infant Delivery Date Baby A DataTime
This is the query in SQL
PARAMETERS [start date] DateTime, [end date] DateTime;
TRANSFORM Count(LDExport.[Method of Delivery Baby A]) AS [CountOfMethod of Delivery Baby A]
SELECT IIf(([PT-AGE]>=8 And [PT-AGE]<15),"Ages 8-14",
IIf(([PT-AGE]>=15 And [PT-AGE]<20),"Ages 15-20",
IIf(([PT-AGE]>=20 And [PT-AGE]<25),"Ages 20-24",
IIf(([PT-AGE]>=25 And [PT-AGE]<30),"Ages 25-29",
IIf(([PT-AGE]>=30 And [PT-AGE]<35),"Ages 30-34",
IIf(([PT-AGE]>=35 And [PT-AGE]<40),"Ages 35-39",
IIf(([PT-AGE]>=40 And [PT-AGE]<45),"Ages 40-44",
IIf(([PT-AGE]>=45 And [PT-AGE]<65),"Ages 45-64","unknown"))))))))
AS [Age Group]
FROM LDExport
WHERE (((LDExport.[Infant Delivery Date Baby A DateTime])>=[start date] And (LDExport.[Infant Delivery Date Baby A DateTime])<[end date]))
GROUP BY LDExport.[PT-AGE], LDExport.[Infant Delivery Date Baby A DateTime], IIf(([PT-AGE]>=8 And [PT-AGE]<15),"Ages 8-14",IIf(([PT-AGE]>=15 And [PT-AGE]<20),"Ages 15-20",IIf(([PT-AGE]>=20 And [PT-AGE]<25),"Ages 20-24",IIf(([PT-AGE]>=25 And [PT-AGE]<30),"Ages 25-29",IIf(([PT-AGE]>=30 And [PT-AGE]<35),"Ages 30-34",IIf(([PT-AGE]>=35 And [PT-AGE]<40),"Ages 35-39",IIf(([PT-AGE]>=40 And [PT-AGE]<45),"Ages 40-44",IIf(([PT-AGE]>=45 And [PT-AGE]<65),"Ages 45-64","unknown"))))))))
PIVOT LDExport.[Method of Delivery Baby A] In ("C/S","Vag");
I know that its kind of jumbled up. I am still at the stage where I need to build complicated queries in the access grid
The last bit highlighted in red from what I understand, should make this work in an access report.
but when I run it, i get a parameter error
I know this query works as a crosstab query however.
any help appreciated.
btw the results should be a crosstab that is basically
age category - total vag deliveries - total C/S deliveries
edit,
I should clarify, I have to use 2 queries to produce the crosstab as regular queries
I created a crosstab query that more or less works fine.
Due to how the databases i have to work with are set up, I have been trying to move some of my custom queries to access reports because it will automatically do a lot of the formatting and such that I would otherwise have to do manually with the query results over in word or excel.
In order to get a crosstab query to work in an access report, from what I understand I need to specify all column headings, at least that is what random googling and access error messages are telling me (note I am also trying to teach myself to do more and more of this in sql, because if I get my project approved, I get a real sql database for my emr records, as opposed to the situation I deal with now, anyway).
The table it pulls from LDExport
It uses the fields
PT-AGE
Method of Delivery Baby A
Infant Delivery Date Baby A DataTime
This is the query in SQL
PARAMETERS [start date] DateTime, [end date] DateTime;
TRANSFORM Count(LDExport.[Method of Delivery Baby A]) AS [CountOfMethod of Delivery Baby A]
SELECT IIf(([PT-AGE]>=8 And [PT-AGE]<15),"Ages 8-14",
IIf(([PT-AGE]>=15 And [PT-AGE]<20),"Ages 15-20",
IIf(([PT-AGE]>=20 And [PT-AGE]<25),"Ages 20-24",
IIf(([PT-AGE]>=25 And [PT-AGE]<30),"Ages 25-29",
IIf(([PT-AGE]>=30 And [PT-AGE]<35),"Ages 30-34",
IIf(([PT-AGE]>=35 And [PT-AGE]<40),"Ages 35-39",
IIf(([PT-AGE]>=40 And [PT-AGE]<45),"Ages 40-44",
IIf(([PT-AGE]>=45 And [PT-AGE]<65),"Ages 45-64","unknown"))))))))
AS [Age Group]
FROM LDExport
WHERE (((LDExport.[Infant Delivery Date Baby A DateTime])>=[start date] And (LDExport.[Infant Delivery Date Baby A DateTime])<[end date]))
GROUP BY LDExport.[PT-AGE], LDExport.[Infant Delivery Date Baby A DateTime], IIf(([PT-AGE]>=8 And [PT-AGE]<15),"Ages 8-14",IIf(([PT-AGE]>=15 And [PT-AGE]<20),"Ages 15-20",IIf(([PT-AGE]>=20 And [PT-AGE]<25),"Ages 20-24",IIf(([PT-AGE]>=25 And [PT-AGE]<30),"Ages 25-29",IIf(([PT-AGE]>=30 And [PT-AGE]<35),"Ages 30-34",IIf(([PT-AGE]>=35 And [PT-AGE]<40),"Ages 35-39",IIf(([PT-AGE]>=40 And [PT-AGE]<45),"Ages 40-44",IIf(([PT-AGE]>=45 And [PT-AGE]<65),"Ages 45-64","unknown"))))))))
PIVOT LDExport.[Method of Delivery Baby A] In ("C/S","Vag");
I know that its kind of jumbled up. I am still at the stage where I need to build complicated queries in the access grid
The last bit highlighted in red from what I understand, should make this work in an access report.
but when I run it, i get a parameter error
I know this query works as a crosstab query however.
any help appreciated.
btw the results should be a crosstab that is basically
age category - total vag deliveries - total C/S deliveries
edit,
I should clarify, I have to use 2 queries to produce the crosstab as regular queries
Last edited: