sql server - T-SQL code to add 7 days to a date -
If we recall the date of the ship, the details given below include 7 days on the date of shipment. For, 07/24/2014
did not send any vessel to the ship for any reason. The following query in shipments adds 7 days (as a result of 07/31/2014
).
The only problem is that the 'test ship' column adds seven days to shipment if we remember the date of shipment, only on Sunday the date. What do I mean for jobs that was the date of a scheduled ship of 07/24/2014
, and we miss the job navigations on that day, update the next scheduled ship next to the 'test ship' column Does 07/31/2014
only on Sunday.
For example, the job J012345
is 07/24/2014 / 2014
. Then the 'Test Ship' column will update tomorrow's date.e 07/27/2014
(Sunday) instead of updating it on Friday 07/25/2014
Am I missing anything here? How do I get a 'test ship' to update on Sunday on Sunday?
'test ship' = case when J. Jobstats & lt; & Gt; 'S' and the cast (X. Date Date) & lt; DATEADD (wk, DATEDIFF (wk, 3, CAST (GETDATE (AS) date)), 3) Then DATEADD (DAY, 4, CAST (DATEADD (week, DATEDIFF (week, 0, GETDATE ()), -1) AS Date)) WHEN j.JobStatus = 'S' then cast (j.LastShippedDate as date) ELSE CAST (x.ExpectedDate as date) END
View the solutions posted, which can be summarized as:
-
By separating the case, reading the code Make Easy
Conditions
- Replace non-deterministic function (
getdate ()
) with a determinant solution - Replace non-deterministic function (
Comments
Post a Comment