SELECT * FROM MSMST WHERE CASE WHEN CONVERT(VARCHAR(4), GETDATE(),112)+RIGHT(BIRTH,4) <= CONVERT(VARCHAR(8), GETDATE(), 112)
THEN CONVERT(VARCHAR(8),DATEADD(YEAR, +1, GETDATE()), 112)+RIGHT(BIRTH,4)
ELSE CONVERT(VARCHAR(4), GETDATE(),112)+RIGHT(BIRTH,4) END
BETWEEN CONVERT(VARCHAR(8), GETDATE(), 112) AND CONVERT(VARCHAR, DATEADD(DAY, 20, GETDATE()) , 112 )
기존소스... 돌아가긴하나 쿼리속도가 엄청느림..
by 우리집아찌
[2013.10.31 18:11:14]
WITH t AS
(
SELECT '19831224' BIRTH_DAY FROM DUAL UNION ALL
SELECT '19831030' BIRTH_DAY FROM DUAL
)
SELECT TRUNC( TO_DATE( SUBSTR(BIRTH_DAY,5,4) , 'MMDD' ) - SYSDATE)
FROM t
by 우리집아찌
[2013.10.31 18:11:33]
아 MS-SQL 이시구나..
by 김성진
[2013.11.13 16:29:34]
WITH MSMST AS ( SELECT '홍길동' UserName,CAST('20131103' AS DATETIME) BIRTH UNION ALL SELECT '홍길동1' UserName,CAST('20131113' AS DATETIME) BIRTH UNION ALL SELECT '홍길동2' UserName,CAST('20131123' AS DATETIME) BIRTH ) SELECT *, DATEDIFF(DAY, BIRTH, GETDATE()) DIFF FROM MSMST WHERE DATEDIFF(DAY, BIRTH, GETDATE()) BETWEEN 0 AND 10
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.