首先要有一个FUNCTION判断是不是BUSINESS DATE,别忘了HOLIDAY
create function [dbo].[udf_is_valid_business_date]
(
@date datetime
)
returns int
as
begin
declare
@is_holiday int,
@is_valid_business_date int
select @is_holiday =
case
-- memorial day (last mon of may)
when datepart(yy,@date) = 2009 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 25 then 1
when datepart(yy,@date) = 2010 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 31 then 1
when datepart(yy,@date) = 2011 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 30 then 1
when datepart(yy,@date) = 2012 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 28 then 1
when datepart(yy,@date) = 2013 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 27 then 1
when datepart(yy,@date) = 2014 and datepart(mm,@date) = 5 and
datepart(dd,@date) = 26 then 1
-- thanksgiving (last thu of nov plus 1 day after that)
when datepart(yy,@date) = 2008 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (27, 28) then 1
when datepart(yy,@date) = 2009 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (26, 27) then 1
when datepart(yy,@date) = 2010 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (25, 26) then 1
when datepart(yy,@date) = 2011 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (24, 25) then 1
when datepart(yy,@date) = 2012 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (29, 30) then 1
when datepart(yy,@date) = 2013 and datepart(mm,@date) = 11 and
datepart(dd,@date) in (28, 29) then 1
-- labor day (1st mon of Sep)
when datepart(yy,@date) = 2008 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 1 then 1
when datepart(yy,@date) = 2009 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 7 then 1
when datepart(yy,@date) = 2010 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 6 then 1
when datepart(yy,@date) = 2011 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 5 then 1
when datepart(yy,@date) = 2012 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 3 then 1
when datepart(yy,@date) = 2013 and datepart(mm,@date) = 9 and
datepart(dd,@date) = 2 then 1
-- 4th of July (every year)
when datepart(mm,@date) = 7 and datepart(dd,@date) = 4 then 1
-- Xmas (25 dec every year)
when datepart(mm,@date) = 12 and datepart(dd,@date) = 25 then 1
-- New Years (1 jan every year)
when datepart(mm,@date) = 1 and datepart(dd,@date) = 1 then 1
--
else 0
end
-- Everytime we encouter a weekend day or holiday, we must add one day
to the shipping estimate
if( (datepart(dw, @date) = 1) or (datepart(dw, @date) = 7) or (@is_
holiday = 1) )
begin
select
@is_valid_business_date = 0
end
else
begin
select
@is_valid_business_date = 1
end
return @is_valid_business_date
end