您的位置:首页 > 其它

判断 节假日 终极解决方案(带五一 十一,端午节,春节,清明节)

2009-06-24 23:24 471 查看
if exists (select * from dbo.sysobjects where id = object_id(N'[tb_Holiday]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [tb_Holiday]
GO
create table tb_Holiday(id int IDENTITY(1,1) NOT NULL primary key clustered,HolidayDate smalldatetime,HolidayName nvarchar(50) not null,Holidayvalue bigint not null,Type char(1) not null)
Go
Insert into tb_Holiday(HolidayDate,HolidayName,Holidayvalue,Type)
select '2009-01-01','元旦',1,'1'
union all select '2009-01-02','元旦',1,'1'
union all select '2009-01-03','元旦',1,'1'
union all select '2009-01-04','公休(周末)',128,'0'
union all select '2009-01-25','春节',2,'1'
union all select '2009-01-26','春节',2,'1'
union all select '2009-01-27','春节',2,'1'
union all select '2009-01-28','春节',2,'1'
union all select '2009-01-29','春节',2,'1'
union all select '2009-01-30','春节',2,'1'
union all select '2009-01-31','春节',2,'1'
union all select '2009-01-24','公休(周末)',128,'0'
union all select '2009-02-01','春节',2,'0'
union all select '2009-04-04','清明节',4,'1'
union all select '2009-04-05','清明节',4,'1'
union all select '2009-04-06','清明节',4,'1'
union all select '2009-05-01','劳动节',8,'1'
union all select '2009-05-02','劳动节',8,'1'
union all select '2009-05-03','劳动节',8,'1'
union all select '2009-05-28','端午节',16,'1'
union all select '2009-05-29','端午节',16,'1'
union all select '2009-05-30','端午节',16,'1'
union all select '2009-05-31','公休(周末)',128,'0'
union all select '2009-10-01','国庆节、中秋节',32,'1'
union all select '2009-10-02','国庆节、中秋节',32,'1'
union all select '2009-10-03','国庆节、中秋节',32,'1'
union all select '2009-10-04','国庆节、中秋节',32,'1'
union all select '2009-10-05','国庆节、中秋节',32,'1'
union all select '2009-10-06','国庆节、中秋节',32,'1'
union all select '2009-10-07','国庆节、中秋节',32,'1'
union all select '2009-10-08','国庆节、中秋节',32,'1'
union all select '2009-09-27','公休(周末)',128,'0'
union all select '2009-10-10','公休(周末)',128,'0'
union all select '2010-01-01','元旦',1,'1'
union all select '2010-01-02','元旦',1,'1'
union all select '2010-01-03','元旦',1,'1'

select distinct(HolidayName) from tb_Holiday where HolidayDate >=convert(datetime,'2009-2-2') and HolidayDate <= convert(datetime,'2009-5-30') or Holidayvalue =128

CREATE FUNCTION [dbo].[fnCheckDate](@solarDay DATETIME)
RETURNS bigint AS
BEGIN
DECLARE @OUTPUTDATA Bigint --返回数值
SET @OUTPUTDATA = 0 --初始化为非假日
select @OUTPUTDATA=@OUTPUTDATA|Holidayvalue from tb_Holiday where Holidayvalue<>128 and HolidayDate=@solarDay
IF (@OUTPUTDATA = 0)
Begin
IF (@@DATEFIRST+DATEPART(Weekday,@solarDay)-1)%7 in(0,6) And not Exists(select * from tb_Holiday where HolidayDate=@solarDay and Type='0')
select @OUTPUTDATA = 128
End
Return @OUTPUTDATA
END
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: