I've checked the threads and the faqs but haven't been able to get my query to work right.
The basic sql is:
When I run that sql it gives me the data type mismatch message.
However, if I use an account number and a date as a criteria it will run:
The criteria subqueries are there because account price and diff(erentials) change over time and the right figure needs to be applied for each transaction. If I run the query without tblAccountDiff it works so somehow that extra querying must have something to do with it.
I've been playing with it for hours and I'm sure it has something to do with the criteria subqueries but can't put my finger on the solution.
All help is appreciated but I am leaving for the day soon so I probably won't see replies until tomorrow.
Bear
The basic sql is:
Code:
SELECT DISTINCT T.AcctNum, T.Date, T.Time, T.SiteId, CDbl([Qty]) AS Qty1, tblAccountDiff.EffectiveDate
FROM (qryTransactionFieldsForQueriesWithPriceDateAndDiff AS T INNER JOIN tblPrice AS P ON T.SiteId = P.SiteID) INNER JOIN tblAccountDiff ON T.AcctNum = tblAccountDiff.AccountNum
WHERE (((tblAccountDiff.EffectiveDate)=(SELECT cdate(format( Max([EffectiveDate]), "short date")) FROM tblAccountDiff WHERE AccountNum=T.AcctNum AND format( [EffectiveDate],"mmddyyyy")<=format(T.Date,"mmddyyyy"))) AND ((P.PriceDate)=(SELECT Max([PriceDate]) FROM tblPrice WHERE SiteID=T.SiteID AND format( [PriceDate],"short date")<=format(T.Date,"short date"))))
ORDER BY T.AcctNum, T.SiteId;
When I run that sql it gives me the data type mismatch message.
However, if I use an account number and a date as a criteria it will run:
Code:
SELECT DISTINCT T.AcctNum, T.Date, T.Time, T.SiteId, CDbl([Qty]) AS Qty1, tblAccountDiff.EffectiveDate
FROM (qryTransactionFieldsForQueriesWithPriceDateAndDiff AS T INNER JOIN tblPrice AS P ON T.SiteId = P.SiteID) INNER JOIN tblAccountDiff ON T.AcctNum = tblAccountDiff.AccountNum
WHERE (((T.AcctNum)="102870-2") AND ((T.Date)>#5/1/2007#) AND ((tblAccountDiff.EffectiveDate)=(SELECT cdate(format( Max([EffectiveDate]), "short date")) FROM tblAccountDiff WHERE AccountNum=T.AcctNum AND format( [EffectiveDate],"mmddyyyy")<=format(T.Date,"mmddyyyy"))) AND ((P.PriceDate)=(SELECT Max([PriceDate]) FROM tblPrice WHERE SiteID=T.SiteID AND format( [PriceDate],"short date")<=format(T.Date,"short date"))))
ORDER BY T.AcctNum, T.SiteId;
The criteria subqueries are there because account price and diff(erentials) change over time and the right figure needs to be applied for each transaction. If I run the query without tblAccountDiff it works so somehow that extra querying must have something to do with it.
I've been playing with it for hours and I'm sure it has something to do with the criteria subqueries but can't put my finger on the solution.
All help is appreciated but I am leaving for the day soon so I probably won't see replies until tomorrow.
Bear