关于数据类型的转换问题
现在有两张表一张是表类型,一张是公农历对照表:
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');--创建表类型GOIF TYPE_ID('tyWeekday') IS NOT NULLDROP TYPE tyWeekday;GOCREATE 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');--创建表类型GOIF TYPE_ID('tyWeekday') IS NOT NULLDROP TYPE tyWeekday;GOCREATE 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;-- resultId HolidayDate----------- -----------------------1 2013-02-10 00:00:00.000