crosstab query

crosstab query

Post by John Bake » Wed, 27 Feb 2002 00:22:30



I have a  made a crosstab query in access which is causing me some
heartache. The query works fine until  I try and introduce an extra field as
a  row heading and group by. The field is "fldEquipmentType".
The query actually runs, but then gives me an error of :  "Datatype mismatch
in criteria expression".
A dialogbox comes up with the error message and when I press OK every cell
in the query becomes "#Name?"

The SQL for the query is:

PARAMETERS [Forms]![frmReportDatesDialogBox]![BeginningDate] DateTime,
[Forms]![frmReportDatesDialogBox]![EndingDate] DateTime;
TRANSFORM [fldPower]*Format(Count([fldStatusCode]),"0") AS TotalPower
SELECT [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
[qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower,
Format(Avg([TotalPower]),"0.0") AS Average
FROM [qryUtilisation&EquipmentCodesAllDepotsOnly]
GROUP BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
[qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
ORDER BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
PIVOT Format([fldDate],"ddd") In
("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

Please Note: the parameters are required to run the base query
"qryUtilisation&EquipmentCodesAllDepotsOnly"

Can anyone suggest what is wrong?
Any help greatly appreciated.

John Baker

 
 
 

crosstab query

Post by Duane Hooko » Wed, 27 Feb 2002 13:24:46


I would go back to qryUtilisation&EquipmentCodesAllDepotsOnly and run this
query to see what type of values are displaying in the fldEquipmentType
column. You may need to explicitly convert the values using Nz() or some
other function. Are the values numeric or text? Are there null values?

Duane


Quote:

> I have a  made a crosstab query in access which is causing me some
> heartache. The query works fine until  I try and introduce an extra field
as
> a  row heading and group by. The field is "fldEquipmentType".
> The query actually runs, but then gives me an error of :  "Datatype
mismatch
> in criteria expression".
> A dialogbox comes up with the error message and when I press OK every cell
> in the query becomes "#Name?"

> The SQL for the query is:

> PARAMETERS [Forms]![frmReportDatesDialogBox]![BeginningDate] DateTime,
> [Forms]![frmReportDatesDialogBox]![EndingDate] DateTime;
> TRANSFORM [fldPower]*Format(Count([fldStatusCode]),"0") AS TotalPower
> SELECT [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
> [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower,
> Format(Avg([TotalPower]),"0.0") AS Average
> FROM [qryUtilisation&EquipmentCodesAllDepotsOnly]
> GROUP BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
> [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
> ORDER BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
> PIVOT Format([fldDate],"ddd") In
> ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

> Please Note: the parameters are required to run the base query
> "qryUtilisation&EquipmentCodesAllDepotsOnly"

> Can anyone suggest what is wrong?
> Any help greatly appreciated.

> John Baker


 
 
 

crosstab query

Post by John Bake » Wed, 27 Feb 2002 16:07:51


Thanks Duane. You certainly gave me hope and something to work on.

I have been thru the original tables and made sure all relevant entries
are not null. However it seems to make know difference to the crosstab
query.

Do you have any other ideas?

Thanks John

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

crosstab query

Post by John Bake » Wed, 27 Feb 2002 20:59:38


Thanks Duane. You certainly gave me hope and something to work on. Thankyou.
I've now made sure there are no null values in both the original table that
I use. However the problem still persists and the error message is exactly
the same. Do you have any other ideas?

John.


> I would go back to qryUtilisation&EquipmentCodesAllDepotsOnly and run this
> query to see what type of values are displaying in the fldEquipmentType
> column. You may need to explicitly convert the values using Nz() or some
> other function. Are the values numeric or text? Are there null values?

> Duane



> > I have a  made a crosstab query in access which is causing me some
> > heartache. The query works fine until  I try and introduce an extra
field
> as
> > a  row heading and group by. The field is "fldEquipmentType".
> > The query actually runs, but then gives me an error of :  "Datatype
> mismatch
> > in criteria expression".
> > A dialogbox comes up with the error message and when I press OK every
cell
> > in the query becomes "#Name?"

> > The SQL for the query is:

> > PARAMETERS [Forms]![frmReportDatesDialogBox]![BeginningDate] DateTime,
> > [Forms]![frmReportDatesDialogBox]![EndingDate] DateTime;
> > TRANSFORM [fldPower]*Format(Count([fldStatusCode]),"0") AS TotalPower
> > SELECT [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
> > [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower,
> > Format(Avg([TotalPower]),"0.0") AS Average
> > FROM [qryUtilisation&EquipmentCodesAllDepotsOnly]
> > GROUP BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldEquipmentType,
> > [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
> > ORDER BY [qryUtilisation&EquipmentCodesAllDepotsOnly].fldPower
> > PIVOT Format([fldDate],"ddd") In
> > ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

> > Please Note: the parameters are required to run the base query
> > "qryUtilisation&EquipmentCodesAllDepotsOnly"

> > Can anyone suggest what is wrong?
> > Any help greatly appreciated.

> > John Baker

 
 
 

1. multiple queries into a crosstab query in VB

I have the following 4 queries in A97 that I would like to be able to
do in VB6 using ADO

This is the first query, it is called 'setup Grand total  per day'
SELECT DWN.Dte, WSTN.Description, Sum(DWN.Duration) AS GrandTotalTime
FROM (DWN INNER JOIN WSTN ON DWN.WstnID = WSTN.WstnID) INNER JOIN
Major ON (DWN.MajID = Major.MajID) AND (DWN.WstnID = Major.WstnID)
GROUP BY DWN.Dte, WSTN.Description
ORDER BY DWN.Dte, WSTN.Description;

This is the secod query, it is called 'setup total  Production per
day'
SELECT DWN.Dte, WSTN.Description, Sum(DWN.Duration) AS
TotalProducingTime
FROM (DWN INNER JOIN WSTN ON DWN.WstnID = WSTN.WstnID) INNER JOIN
Major ON (DWN.MajID = Major.MajID) AND (DWN.WstnID = Major.WstnID)
GROUP BY DWN.Dte, WSTN.Description, Major.Descr
HAVING (((Major.Descr)="PRODUCING"))
ORDER BY DWN.Dte, WSTN.Description;

The above 2 queries get linked together to form the third query, it is
called 'Setup Crosstab Downtime by day by workstation'
SELECT [setup Grand total  per day].Dte, [setup Grand total  per
day].Description, [GrandTotalTime]-[TotalProducingTime] AS DownTime
FROM [setup Grand total  per day] INNER JOIN [setup total  Production
per day] ON ([setup Grand total  per day].Dte = [setup total
Production per day].Dte) AND ([setup Grand total  per day].Description
= [setup total  Production per day].Description);

the results of the third query are processed in the fourth query, a
crosstab, called 'Crosstab_Downtime_by_day_by_workstation'
TRANSFORM Sum([Setup Crosstab Downtime by day by
workstation].DownTime) AS [The Value]
SELECT [Setup Crosstab Downtime by day by workstation].Dte
FROM [Setup Crosstab Downtime by day by workstation]
GROUP BY [Setup Crosstab Downtime by day by workstation].Dte
PIVOT [Setup Crosstab Downtime by day by workstation].Description;

To get the above to work in VB6 thus far I have done the following

adoWaiver.ConnectionString = conStringOFIR
adoWaiver.RecordSource = "Crosstab_Downtime_by_day_by_workstation"
adoWaiver.Refresh

Set TDBGrid1.DataSource = adoWaiver
TDBGrid1.Refresh
TDBGrid1.ReBind
TDBGrid1.Refresh

This all works fine by as you can see, the query that I am calling,
query 4 above actually resides in the A97 database. I do not wish to
have it in the database at all as I want to code it up in pure VB. Can
somesome please show me how I could code up the above 4 queries into 1
superquery so that I can get the results of the crosstab into my True
Db Grid control.

PS
That dates are comming back in American format m/dd/yy, which play
havoc when trying to load the results up into excel under Australian
format 'dd/mm/yyyy'. I need to get the results into excel as
'dd/mm/yyyy'. Does anyone know how to fix this ?

Thanks
Stu-man

2. Deleting DAO Database Records

3. DATA WAREHOUSE @ SYBASE CORP, MOST CITIES

4. Fake a crosstab query

5. Test A: drive for disk

6. Can I use crosstab query in ADP?

7. Crosstab Query?

8. Crosstab Query

9. crosstab query

10. Crosstab Query Question -- Thanks

11. Crosstab Queries