0

I've got an inventory report I'm working with which calculates our average weekly consumption of a particular part and then divides it by what we have on hand to show us a numerical "weeks on hand". So if we have an average weekly consumption of 496 and we have 1500 pieces available, the weeks on hand should be 3.02.

What I'm trying to do is take that number and calculate exactly which day we'll run out of the part in question. So we'd run out of the example part in 3.02 weeks from now. My issue is that I have to exclude Fridays - Sundays, so each work week is only four days.

I've looked at the DATEADD() function, and this seems to be what I need to use, but I'm just not sure how to exclude the Fridays from it. I'm using SQL 2005 for this.

Many thanks!

4

1 回答 1

0
DECLARE @old_dt SMALLDATETIME
SET @old_dt = GETDATE()
DECLARE @new_dt SMALLDATETIME
SET @new_dt = DATEADD(d,CAST(3.2*7 AS INT),@old_dt)
SELECT CASE WHEN DATENAME(weekday,@new_dt) = 'Thursday' THEN DATEADD(d,2,@new_dt) WHEN  DATENAME(weekday,@new_dt) = 'Friday' THEN DATEADD(d,1,@new_dt) ELSE @new_dt END
于 2011-10-03T19:46:58.700 回答