Hi,
I have a query I been working on and finnaly got it to pull the last 20 days, so the query returns from today 20 days back. My porblem is that I need the last 20 weekdays. Currently the script is counting weekend days so if I run the script today I get 13 weekdays (Mon -Fri) and I really need the last 20 weekdays so no matter when the script runs it should always return the last 20 days
Here isthe code I have so far
Thanks in advance for any help
RJL1
I have a query I been working on and finnaly got it to pull the last 20 days, so the query returns from today 20 days back. My porblem is that I need the last 20 weekdays. Currently the script is counting weekend days so if I run the script today I get 13 weekdays (Mon -Fri) and I really need the last 20 weekdays so no matter when the script runs it should always return the last 20 days
Here isthe code I have so far
Code:
SELECT
CONVERT (VARCHAR(30),L.DATE_TIME_STAMP,101) AS 'LAUNCH_DATE',
DATENAME(DW,L.DATE_TIME_STAMP) AS 'WEEKDAY',
COUNT(DISTINCT SD.SHIPMENT_ID) AS 'ORDERS',
COUNT(SD.ERP_ORDER_LINE_NUM) AS 'LINES',
SUM(SD.TOTAL_QTY) AS 'UNITS',
SUM(dbo.adcMR_UWT_GetCaseQty(SD.ITEM,SD.QUANTITY_UM,SD.TOTAL_QTY)) AS 'PK2CS'
FROM
LAUNCH_STATISTICS L WITH(NOLOCK)
JOIN SHIPMENT_DETAIL SD ON SD.LAUNCH_NUM = L.INTERNAL_LAUNCH_NUM
WHERE
CONVERT (VARCHAR(30),L.DATE_TIME_STAMP,101) >= DATEADD(DAY, -20, CONVERT (VARCHAR(30),GETDATE(),101))
GROUP BY
CONVERT (VARCHAR(30),L.DATE_TIME_STAMP,101),
DATENAME(DW,L.DATE_TIME_STAMP)
ORDER BY
CONVERT (VARCHAR(30),L.DATE_TIME_STAMP,101)
Thanks in advance for any help
RJL1