---sql server 2005 測試 塗聚文 捷為工作室,締友計算機信息技術有限公司 ---查找公曆節日 --select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@week and GooddayWeekdays=@Day and GooddayUidKey='F0FAFC87-F492-455F-B56E-358917658B6E' select * from GoodDaysList declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier set @setDate='2012-12-01' --設置現在的日期 set @year=Year(@setDate) set @month=Month(@setDate) set @day=DAy(@setDate) set @weeks=DAy(@setDate) set @GooddayUidKey='D9C5D984-6AEB-4EE4-B332-82F7E878D539' select @year as '日',@month as '月',@day as '日' select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey ---查找農日節日 測試 塗聚文 捷為工作室,締友計算機信息技術有限公司 ---1700年之前的节日需要用sql server 2008之後版本才行,Access 也行 select dbo.fn_GetLunarNumber('2012-06-23') --農曆查公曆 select dbo.fn_GetDate('2012-05-05') select * from dbo.GoodDayClass declare @setDate datetime,@Lunaryear int,@Lunarmonth int,@Lunarday int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@LunarDate datetime set @setDate='2012-06-23' --設置現在的公曆日期 select @LunarDate=dbo.fn_GetLunarNumber(@setDate) set @Lunaryear=Year(@LunarDate) set @Lunarmonth=Month(@LunarDate) set @Lunarday=DAy(@LunarDate) set @weeks=DAy(@LunarDate) set @GooddayUidKey='F25835BF-3918-4201-BB8D-BD82F737EF8A' select @LunarDate as '農日日期',@Lunaryear as '農曆年',@Lunarmonth as '農曆月',@Lunarday as '農曆日' select (@Lunaryear-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @Lunaryear>=GooddayStaryear and GooddayStarmoth=@Lunarmonth and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey select * from dbo.GoodDaysList ---查找周節日 declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@weekdayname varchar(10) set @setDate='2012-05-06' --設置現在的日期 set @year=Year(@setDate) set @month=Month(@setDate) set @day=DAy(@setDate) select @weeks=DATEPART(WEEK,@setDate)-DATEPART(WEEK,DATEADD(MONTH,DATEDIFF(MONTH,0,@setDate),0))+1 --月中周幾 select @weekday=DATEPART(weekday,@setDate)-1 --周幾(0星期天,1星期一,2星期二) select @weekdayname=DATENAME(weekday,@setDate) --周幾 set @GooddayUidKey='F25835BF-3918-4201-BB8D-BD82F737EF8A' select @year as '年',@month as '月',@weeks as '月中第幾周',@weekday as '周幾',@weekdayname as '周幾' select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayWeekdays=@weekday and GooddayUidKey=@GooddayUidKey --查找年中第多少日的節日(如程序員節) 其它節日在此略