IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE XTYPE = 'U' AND NAME = 'T_CARLENDAR')
BEGIN
DROP TABLE T_CARLENDAR
END
CREATE TABLE DBO.T_CARLENDAR
(
TYEAR NVARCHAR(4),
TMONTH NVARCHAR(2),
TDAY NVARCHAR(2),
TDW NVARCHAR(30),
HOLIDAYBOOL BIT DEFAULT 0,
HOLIDAYINFO NVARCHAR(100),
MEMO TEXT
)
DECLARE @LASTDATETIME DATETIME
SET @LASTDATETIME = '2015-12-31'
DECLARE @DATETIME DATETIME
SET @DATETIME = '2012-11-01'
WHILE @LASTDATETIME >= @DATETIME
BEGIN
INSERT T_CARLENDAR
(
TYEAR,TMONTH,TDAY,TDW,HOLIDAYINFO,HOLIDAYBOOL
)
SELECT DATENAME(YYYY,@DATETIME) AS TYEAR,
DATENAME(MM,@DATETIME) AS TMONTH,
CASE WHEN LEN(DATENAME(DD,@DATETIME)) = 1 THEN '0' + DATENAME(DD,@DATETIME) ELSE DATENAME(DD,@DATETIME) END AS TDAY,
DATENAME(DW,@DATETIME) AS TDW,
CASE WHEN DATENAME(DW,@DATETIME) IN ('토요일','일요일') THEN '휴무일' ELSE NULL END AS HOLIDAYINFO,
CASE WHEN DATENAME(DW,@DATETIME) IN ('토요일','일요일') THEN 1 ELSE 0 END AS HOLIDAYBOOL
SET @DATETIME = DATEADD(DAY,1,@DATETIME)
END
SELECT * FROM T_CARLENDAR
'MS-SQL > Query' 카테고리의 다른 글
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 옵션 (0) | 2013.02.05 |
---|---|
MS-SQL 2005 테이블 이름을 검색하여 특정 테이블 찾기 (0) | 2013.02.05 |
데이터베이스 연결 간단한 예제 (0) | 2013.02.05 |
bak파일 복원 예제 (0) | 2013.02.04 |
BACKUP ,RESTORE 명령어로 데이터베이스 복사 (0) | 2013.02.04 |