Hello All,
I've a SSRS report with the details in regards to shipping information. Currently in my report the 'Scheduled Ship Date' is set to following Monday, if we miss the 'Requested Delivery Date'. However, I need to change this report to set shipment date('Scheduled
Ship Date') to Tuesday and Friday for the shipment having 'Requested Delivery Date' for this week or next week(current week and next week). For example- Jobs that have shipment date between 3/1/2015 - 3/7/2015 will have 'Scheduled Ship Date' as Tuesday and
Friday of current week. If we miss the shipment for this week it should be scheduled for next Tuesday(3/9/2015) and Friday (3/13/2015). I need to follow this for current week(3/1/2015-3/8/2015) and following week(3/9/2015-3/15/2015) and after that all the
following weeks will have 'Scheduled Ship Date' as Tuesdays.
Can someone please help?
Below is the SQL:
USE tempdb;
GO
DECLARE @Date datetime;
SET @Date = GETDATE();
--SET @Date = '2014-07-25';
DECLARE @TEST_DATA TABLE
(
DT_ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED
,JobNumber VARCHAR(10) NOT NULL
,JobStatus CHAR(1) NOT NULL
,ExpectedDate VARCHAR(10) NOT NULL
,LastShippedDate VARCHAR(10) NULL
);
INSERT INTO @TEST_DATA (JobStatus, JobNumber,ExpectedDate,LastShippedDate)
VALUES
('S', 'J012345','2015-01-23','2015-01-23')
,('S', 'J012346','2015-02-05','2015-02-09')
,('S', 'J012346','2015-03-02','2015-03-03')
,('O', 'J012347','2015-02-19',NULL)
,('O', 'J012347','2015-02-23',NULL)
,('O', 'J012347','2015-02-23',NULL)
,('O', 'J012347','2015-02-24',NULL)
,('O', 'J012348','2015-02-05',NULL)
,('O', 'J012349','2015-02-13',NULL)
,('O', 'J012350','2015-02-13',NULL)
,('O', 'J012351','2015-02-13',NULL)
,('O', 'J012362','2015-02-21',NULL)
,('O', 'J012363','2015-02-21',NULL)
,('O', 'J012364','2015-02-21',NULL)
,('O', 'J012365','2015-03-02',NULL)
,('O', 'J012366','2015-03-06',NULL)
,('O', 'J012372','2015-03-06',NULL)
,('O', 'J012378','2015-03-19',NULL)
,('O', 'J012367','2015-03-19',NULL)
;
SELECT
J.DT_ID
,J.JobStatus /*O-Open, S-Shipped, I-Invoiced*/
,J.ExpectedDate 'Requested Delivery Date'
,J.LastShippedDate
,'Scheduled Ship Date'= CASE
/* SHIPPED - SHOW LastShippedDate */
WHEN j.JobStatus ='S' OR j.JobStatus ='I' OR j.JobStatus ='V' THEN Cast(j.LastShippedDate as DATE)
/* MISSED SHIPMENT SET TO NEXT MONDAY */
WHEN j.JobStatus <>'S' AND DATEDIFF(dd,0,ExpectedDate)/7 <= DATEDIFF(dd,0,@Date) / 7 THEN
DATEADD(DAY,((DATEDIFF(dd,0,@Date)/7) * 7) + 7,0)
/* FUTURE SHIPMENTS */
ELSE CAST(J.ExpectedDate AS DATE)
END
FROM @TEST_DATA J