Hello All,
I am trying to adjust an existing query to automatically run the first week of every month. The issue is that I can't figure out how to automatically select the first and last days of the previous month.
I know how to set the report to run each month but I can't figure out how to change the selection criteria for the month.
SELECT
T3.[DocNum] AS 'Order #'
, T3.[DocStatus] AS 'Document Status'
, T3.[CardCode] AS 'Customer Code'
, T3.[CardName] AS 'Customer Name'
, T3.[DocDate] AS 'Posting Date'
, T3.[TaxDate] AS 'Document Date'
, T3.[DocDueDate] AS 'Due Date'
, T2.[ItemCode] AS 'Item No.'
, T1.[ItemName] AS 'Item Description'
, T1.[ItmsGrpCod] AS 'Item Group'
, T0.[ItmsGrpNam] AS 'Group Name'
, T2.[Quantity] AS 'QTY'
, T4.[Price] AS 'Cost in PriceList'
, T2.[GrossBuyPr] AS 'Cost from Order'
FROM [dbo].[OITB] T0
INNER JOIN [dbo].[OITM] T1 ON T1.[ItmsGrpCod] = T0.[ItmsGrpCod]
INNER JOIN [dbo].[RDR1] T2 ON T2.[ItemCode] = T1.[ItemCode] AND T2.[ItemCode] = T1.[ItemCode]
INNER JOIN [dbo].[ORDR] T3 ON T3.[DocEntry] = T2.[DocEntry]
Left Outer Join ITM1 T4 on T4.PriceList = '23' and T1.ItemCode = T4.ItemCode
WHERE
(T0.[ItmsGrpNam] Like N'%TCN%'
OR T0.[ItmsGrpNam] Like N'%TFN%'
OR T0.[ItmsGrpNam] Like N'%TGN%'
OR T0.[ItmsGrpNam] Like N'%TN2%'
OR T0.[ItmsGrpNam] Like N'%TN3%'
OR T0.[ItmsGrpNam] Like N'%TN5%'
OR T0.[ItmsGrpNam] Like N'%TNA%')
and T3.[DocDate] >='[%0]'
and T3.[DocDate] <='[%1]'
ORDER BY T3.[DocNum]
Thank you for any help.