日期:2014-05-18 浏览次数:20369 次
IF OBJECT_ID('CalendarReference') IS NOT NULL DROP TABLE CalendarReference; GO --日历对照表(公历农历对照表) CREATE TABLE CalendarReference ( Id INT IDENTITY (1,1) NOT NULL , CalendarDate DATETIME NOT NULL , LunarDate DATETIME NOT NULL ); --插入数据 INSERT INTO CalendarReference VALUES ('20130210','20130101'); --创建表类型 GO IF TYPE_ID('tyWeekday') IS NOT NULL DROP TYPE tyWeekday; GO CREATE TYPE tyHoliday AS TABLE (Id INT IDENTITY(1,1), HolidayDate DATETIME);
declare @d char(10), @tyh AS tyHoliday; select @d=CalendarDate from CalendarReference where LunarDate='20130101'; select @d; INSERT INTO @tyh VALUES (@d); SELECT * FROM @tyh;
IF OBJECT_ID('CalendarReference') IS NOT NULL DROP TABLE CalendarReference; GO --日历对照表(公历农历对照表) CREATE TABLE CalendarReference ( Id INT IDENTITY (1,1) NOT NULL , CalendarDate DATETIME NOT NULL , LunarDate DATETIME NOT NULL ); --插入数据 INSERT INTO CalendarReference VALUES ('20130210','20130101'); --创建表类型 GO IF TYPE_ID('tyWeekday') IS NOT NULL DROP TYPE tyWeekday; GO CREATE TYPE tyHoliday AS TABLE (Id INT IDENTITY(1,1), HolidayDate DATETIME); declare @d char(10), @tyh AS tyHoliday; select @d=convert(varchar(30),CalendarDate,120) from CalendarReference where LunarDate='20130101'; INSERT INTO @tyh VALUES (@d); SELECT * FROM @tyh; -- result Id HolidayDate ----------- ----------------------- 1 2013-02-10 00:00:00.000