티스토리 뷰

Database

[MSSQL]이메일 유효성 체크 쿼리

애플자라 2010. 10. 7. 15:39
반응형

-- Before

SELECT COUNT(1) FROM EMS_AUTO_SCHEDULE_INFO A, EMS_AUTO_SEND_LIST_01 B
WHERE A.WORKDAY = B.WORKDAY AND A.SEQNO = B.SEQNO
AND A.WORKDAY = CONVERT(VARCHAR(8),GETDATE(),112)
AND A.SEND_FLAG = '05' AND A.REQ_DATE < GETDATE()
AND DATEADD(MI,+30,B.REG_DATE) <= GETDATE()
AND B.SEND_TIME IS NULL
AND B.TO_EMAIL IS NOT NULL
AND B.TO_EMAIL <> ''

-- After(이메일 형식 X)

SELECT COUNT(1) FROM EMS_AUTO_SCHEDULE_INFO A, EMS_AUTO_SEND_LIST_01 B
WHERE A.WORKDAY = B.WORKDAY AND A.SEQNO = B.SEQNO
AND A.WORKDAY = CONVERT(VARCHAR(8),GETDATE(),112)
AND A.SEND_FLAG = '05' AND A.REQ_DATE < GETDATE()
AND DATEADD(MI,+30,B.REG_DATE) <= GETDATE()
AND B.SEND_TIME IS NULL
AND B.TO_EMAIL IS NOT NULL
AND B.TO_EMAIL <> ''
AND NOT
(CHARINDEX(' ',LTRIM(RTRIM(B.TO_EMAIL))) = 0
AND LEFT(LTRIM(B.TO_EMAIL),1) <> '@'
AND RIGHT(RTRIM(B.TO_EMAIL),1) <> '.'
AND CHARINDEX('.',B.TO_EMAIL,CHARINDEX('@',B.TO_EMAIL)) - CHARINDEX('@',B.TO_EMAIL) > 1
AND LEN(LTRIM(RTRIM(B.TO_EMAIL))) - LEN(REPLACE(LTRIM(RTRIM(B.TO_EMAIL)),'@','')) = 1
AND CHARINDEX('.',REVERSE(LTRIM(RTRIM(B.TO_EMAIL)))) >= 3
AND    (CHARINDEX('.@',B.TO_EMAIL) = 0 AND CHARINDEX('..',B.TO_EMAIL) = 0)
)

-- After(이메일 형식 O)

SELECT COUNT(1) FROM EMS_AUTO_SCHEDULE_INFO A, EMS_AUTO_SEND_LIST_01 B
WHERE A.WORKDAY = B.WORKDAY AND A.SEQNO = B.SEQNO
AND A.WORKDAY = CONVERT(VARCHAR(8),GETDATE(),112)
AND A.SEND_FLAG = '05' AND A.REQ_DATE < GETDATE()
AND DATEADD(MI,+30,B.REG_DATE) <= GETDATE()
AND B.SEND_TIME IS NULL
AND B.TO_EMAIL IS NOT NULL
AND B.TO_EMAIL <> ''
AND
(CHARINDEX(' ',LTRIM(RTRIM(B.TO_EMAIL))) = 0
AND LEFT(LTRIM(B.TO_EMAIL),1) <> '@'
AND RIGHT(RTRIM(B.TO_EMAIL),1) <> '.'
AND CHARINDEX('.',B.TO_EMAIL,CHARINDEX('@',B.TO_EMAIL)) - CHARINDEX('@',B.TO_EMAIL) > 1
AND LEN(LTRIM(RTRIM(B.TO_EMAIL))) - LEN(REPLACE(LTRIM(RTRIM(B.TO_EMAIL)),'@','')) = 1
AND CHARINDEX('.',REVERSE(LTRIM(RTRIM(B.TO_EMAIL)))) >= 3
AND    (CHARINDEX('.@',B.TO_EMAIL) = 0 AND CHARINDEX('..',B.TO_EMAIL) = 0)
)

반응형

'Database' 카테고리의 다른 글

[MSSQL] 테이블 소유자 변경하기  (0) 2010.10.27
[MSSQL] MSSQL2000 DB백업본 복구하기  (0) 2010.10.09
[MSSQL] 날짜 변환 관련  (0) 2010.09.24
[MSSQL] 관리를 위한 쿼리들  (0) 2010.09.24
[ORACLE]OUTER JOIN  (0) 2010.08.26
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함