|
Question : Convert a T-SQL query to JET SQL aka Possible ALIAS Problems.
|
|
Hi Experts I have a query that works just fine and dandy in T-SQL but not so well in JET SQL.
I am not sure how to structure a sub SELECT with an Alias.
My query finds from my product database the oldest items that have been stocktaked and puts twenty at the top of my list. Thus my staff can do a rolling stocktake checking the stock levels of twenty items a day instead of doing a full stocktake by closing the store.
The T-SQL is:
SELECT TOP 20 aud.barcode, aud.description, aud.quantity, audit_date FROM Audit, ( SELECT barcode, description, quantity, MAX(audit_id) AS "Audit_Number" FROM Audit INNER JOIN Stock on Stock.stock_id = audit.stock_id WHERE tran_type = 'SI' AND quantity > 0 GROUP BY barcode, description, quantity ) aud WHERE aud.Audit_Number = Audit.audit_id ORDER BY audit_date
Apart from placing a semi-colon at the end what else must I change to get this query to work in Access? I am guessing that the way aliases are handled in JET SQL is my problem.
|
|
Answer : Convert a T-SQL query to JET SQL aka Possible ALIAS Problems.
|
|
Having read your SQL, might I suggest you try the following in it's stead:
------------------------------------------------------------------------------------------------ SELECT TOP 20 T1.barcode, T1.description, T1.quantity, T1.audit_date FROM Audit AS T1 INNER JOIN Stock AS T2 ON T1.stock_id = T2.stock_id WHERE T1.quantity > 0 AND T2.tran_type = 'SI' ORDER BY T1.audit_date
|
|
|
|