Hi All,
As I am suggesting in my title, I am trying to export from a single table only the current and previous months sales transactions based upon a date field dd/mm/yyyy.
Exporting only current and previous months is straight forward, however if like this month we are in period 1, the current and previous script I have written is not clever enough to export January 2010 and the previous month of December 2009.
My experience is in SQL scripting so the script I have done has been done in the SQL View in Access Query.
Can anyone help with my below script please so it knows if we are in period 1 that the previous month is period 12 of the previous year please?? I think this is tricky but any help would be much appreciated:
My script to export current and previous is:
SELECT Customers.CustCode, Items.ItemCode, Inv_Line.ILineQty, Inv_Line.ILineLineTot, Inv_Line.IlineItemCost, Cstr([Inv_Line].[ILineQty]*[Inv_Line].[IlineItemCost]) AS TotalCost, Invoices.InDate
FROM UsersNew INNER JOIN ((Reps INNER JOIN Customers ON Reps.[ID] = Customers.[CustRepID]) INNER JOIN (Invoices INNER JOIN (Items INNER JOIN Inv_Line ON Items.[ItemID] = Inv_Line.[ILineItemCodeID]) ON Invoices.[InID] = Inv_Line.[IlineInvNoID]) ON Customers.[CustID] = Inv_Line.[ILineAccountID]) ON UsersNew.ID = Invoices.InUserID
WHERE Year([Invoices].[InDate]) = Year(Now())
AND (Month([Invoices].[InDate]) = Month(Now())
OR Month([Invoices].[InDate]) = Month(Now())-1);
Thanks
Paul
As I am suggesting in my title, I am trying to export from a single table only the current and previous months sales transactions based upon a date field dd/mm/yyyy.
Exporting only current and previous months is straight forward, however if like this month we are in period 1, the current and previous script I have written is not clever enough to export January 2010 and the previous month of December 2009.
My experience is in SQL scripting so the script I have done has been done in the SQL View in Access Query.
Can anyone help with my below script please so it knows if we are in period 1 that the previous month is period 12 of the previous year please?? I think this is tricky but any help would be much appreciated:
My script to export current and previous is:
SELECT Customers.CustCode, Items.ItemCode, Inv_Line.ILineQty, Inv_Line.ILineLineTot, Inv_Line.IlineItemCost, Cstr([Inv_Line].[ILineQty]*[Inv_Line].[IlineItemCost]) AS TotalCost, Invoices.InDate
FROM UsersNew INNER JOIN ((Reps INNER JOIN Customers ON Reps.[ID] = Customers.[CustRepID]) INNER JOIN (Invoices INNER JOIN (Items INNER JOIN Inv_Line ON Items.[ItemID] = Inv_Line.[ILineItemCodeID]) ON Invoices.[InID] = Inv_Line.[IlineInvNoID]) ON Customers.[CustID] = Inv_Line.[ILineAccountID]) ON UsersNew.ID = Invoices.InUserID
WHERE Year([Invoices].[InDate]) = Year(Now())
AND (Month([Invoices].[InDate]) = Month(Now())
OR Month([Invoices].[InDate]) = Month(Now())-1);
Thanks
Paul