J
John T Ingato
I have a query "Q2" that depends on data generated by query "Q1". Query SQL
is at bottom of message.
Q1 has a field that calculates the difference between two weeks of inventory
levels to produce a sales quantity figure for that period. If the current
week is greater the the previous week, then it is obvious that the account
received some product and a module function "CalculatedSales" is called to
factor out the received product to generate the sales figure.
I used an "iif" statement in the field to determine if the function needs
calling as follows:
AdjustedSalesThisWeek: IIf(NZ(a.onhand-b.onhand) < 0,
CalculatedSales(b.OnHand,a.OnHand,[Buy Pack]),NZ(a.onhand-b.onhand))
It works perfectly.
The problem is when the second query Q2 try to average the above field
"AdjustedSalesThis Week".
I get an error stating "Data Type Mismatch in Criteria Expression". Its as
if by using the if statement, I no longer have a numerical value.
Any suggestions?
Q2 SQL:
SELECT qryCalculateSalesHistory.StoreNumber,
qryCalculateSalesHistory.SKUNumber,
Avg(qryCalculateSalesHistory.AdjustedSalesThisWeek) AS
AvgOfAdjustedSalesThisWeek,
Avg(qryCalculateSalesHistory.AdjustedSalesThisWeek) AS
AvgOfAdjustedSalesThisWeek1
FROM qryCalculateSalesHistory
GROUP BY qryCalculateSalesHistory.StoreNumber,
qryCalculateSalesHistory.SKUNumber;
Q1 SQL:
SELECT a.StoreNumber, a.SKUNumber, tblProductLine.ItemNumber,
tblProductLine.[Buy Pack], a.ReportDate AS FromDate, b.ReportDate AS ToDate,
a.OnHand, b.OnHand, NZ(a.onhand-b.onhand) AS SalesThisWeek,
IIf(NZ(a.onhand-b.onhand) < 0,CalculatedSales(b.OnHand,a.OnHand,[Buy
Pack]),NZ(a.onhand-b.onhand))
AS AdjustedSalesThisWeek, IIf([salesThisWeek]<0,"PO Rcv'd","") AS [PO
Status]
FROM tblProductLine INNER JOIN ((tbl_HD_2006_852_POS_Data AS a INNER JOIN
tbl_HD_2006_852_POS_Data AS b ON (a.StoreNumber = b.StoreNumber) AND
(a.SKUNumber = b.SKUNumber)) INNER JOIN tblProgramHomeDepot ON b.SKUNumber =
tblProgramHomeDepot.SKU) ON tblProductLine.ItemNumber =
tblProgramHomeDepot.ItemNumber
WHERE (((b.ReportDate)=DateAdd("d",7,[a].[ReportDate])));
is at bottom of message.
Q1 has a field that calculates the difference between two weeks of inventory
levels to produce a sales quantity figure for that period. If the current
week is greater the the previous week, then it is obvious that the account
received some product and a module function "CalculatedSales" is called to
factor out the received product to generate the sales figure.
I used an "iif" statement in the field to determine if the function needs
calling as follows:
AdjustedSalesThisWeek: IIf(NZ(a.onhand-b.onhand) < 0,
CalculatedSales(b.OnHand,a.OnHand,[Buy Pack]),NZ(a.onhand-b.onhand))
It works perfectly.
The problem is when the second query Q2 try to average the above field
"AdjustedSalesThis Week".
I get an error stating "Data Type Mismatch in Criteria Expression". Its as
if by using the if statement, I no longer have a numerical value.
Any suggestions?
Q2 SQL:
SELECT qryCalculateSalesHistory.StoreNumber,
qryCalculateSalesHistory.SKUNumber,
Avg(qryCalculateSalesHistory.AdjustedSalesThisWeek) AS
AvgOfAdjustedSalesThisWeek,
Avg(qryCalculateSalesHistory.AdjustedSalesThisWeek) AS
AvgOfAdjustedSalesThisWeek1
FROM qryCalculateSalesHistory
GROUP BY qryCalculateSalesHistory.StoreNumber,
qryCalculateSalesHistory.SKUNumber;
Q1 SQL:
SELECT a.StoreNumber, a.SKUNumber, tblProductLine.ItemNumber,
tblProductLine.[Buy Pack], a.ReportDate AS FromDate, b.ReportDate AS ToDate,
a.OnHand, b.OnHand, NZ(a.onhand-b.onhand) AS SalesThisWeek,
IIf(NZ(a.onhand-b.onhand) < 0,CalculatedSales(b.OnHand,a.OnHand,[Buy
Pack]),NZ(a.onhand-b.onhand))
AS AdjustedSalesThisWeek, IIf([salesThisWeek]<0,"PO Rcv'd","") AS [PO
Status]
FROM tblProductLine INNER JOIN ((tbl_HD_2006_852_POS_Data AS a INNER JOIN
tbl_HD_2006_852_POS_Data AS b ON (a.StoreNumber = b.StoreNumber) AND
(a.SKUNumber = b.SKUNumber)) INNER JOIN tblProgramHomeDepot ON b.SKUNumber =
tblProgramHomeDepot.SKU) ON tblProductLine.ItemNumber =
tblProgramHomeDepot.ItemNumber
WHERE (((b.ReportDate)=DateAdd("d",7,[a].[ReportDate])));