SQL 生成公曆和農曆對照數據續--创建萬年曆查找各種周期性節日數據

 1 ---sql server 2005  測試 塗聚文 捷為工作室,締友計算機信息技術有限公司
 2 ---查找公曆節日
 3 --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'
 4 select * from GoodDaysList
 5 
 6 declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier
 7 set @setDate='2012-12-01' --設置現在的日期
 8 set @year=Year(@setDate)
 9 set @month=Month(@setDate)
10 set @day=DAy(@setDate)
11 set @weeks=DAy(@setDate)
12 set @GooddayUidKey='D9C5D984-6AEB-4EE4-B332-82F7E878D539'
13 select @year as '',@month as '',@day as ''
14 
15 select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey
16 
17 
18 
19 
20 
21 
22 ---查找農日節日 測試 塗聚文 捷為工作室,締友計算機信息技術有限公司
23 ---1700年之前的节日需要用sql server 2008之後版本才行,Access 也行
24 select  dbo.fn_GetLunarNumber('2012-06-23')
25 --農曆查公曆
26 select dbo.fn_GetDate('2012-05-05')
27 
28  select * from dbo.GoodDayClass
29 
30 declare @setDate datetime,@Lunaryear int,@Lunarmonth int,@Lunarday int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@LunarDate datetime
31 set @setDate='2012-06-23' --設置現在的公曆日期
32 select @LunarDate=dbo.fn_GetLunarNumber(@setDate)
33 set @Lunaryear=Year(@LunarDate)
34 set @Lunarmonth=Month(@LunarDate)
35 set @Lunarday=DAy(@LunarDate)
36 set @weeks=DAy(@LunarDate)
37 set @GooddayUidKey='F25835BF-3918-4201-BB8D-BD82F737EF8A'
38 select @LunarDate as '農日日期',@Lunaryear as '農曆年',@Lunarmonth as '農曆月',@Lunarday as '農曆日'
39 select (@Lunaryear-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @Lunaryear>=GooddayStaryear and GooddayStarmoth=@Lunarmonth and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey
40 
41 
42 ---查找周節日
43 
44 declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@weekdayname varchar(10)
45 set @setDate='2012-05-06' --設置現在的日期
46 set @year=Year(@setDate)
47 set @month=Month(@setDate)
48 set @day=DAy(@setDate)
49 select @weeks=DATEPART(WEEK,@setDate)-DATEPART(WEEK,DATEADD(MONTH,DATEDIFF(MONTH,0,@setDate),0))+1  --月中周幾
50 select @weekday=DATEPART(weekday,@setDate) --周幾(0星期天,1星期一,2星期二)
51 select @weekdayname=DATENAME(weekday,@setDate) --周幾
52 set @GooddayUidKey='D9C5D984-6AEB-4EE4-B332-82F7E878D539'
53 select @year as '',@month as '',@weeks as '月中第幾周',@weekday as '周幾',@weekdayname as '周幾'
54 select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayWeekdays=@weekday and GooddayUidKey=@GooddayUidKey
55 
56 
57 --查找年中第多少日的節日(如程序員節) 其它節日在此略

 web demo: http://www.dusystem.com/Calendar.aspx

posted @ 2012-09-21 11:51  ®Geovin Du Dream Park™  阅读(1018)  评论(0编辑  收藏  举报