BETWEEN 과 CASE 구문 같이 쓰기.

2010. 12. 14. 13:12개발관련기록/SQL Server

반응형
WHERE
AND (E.CD_BEEMP BETWEEN CASE WHEN @CODE_TYPE = 'CD_EMP' OR @CODE_TYPE = 'CD_DEPT' THEN
                      CONVERT(DECIMAL,  @STARTCODE )
                   ELSE
                     E.CD_BEEMP END
                   AND
                   CASE WHEN @CODE_TYPE = 'CD_EMP' OR @CODE_TYPE = 'CD_DEPT' THEN
                       CONVERT(DECIMAL,  @ENDCODE )
                                  --조회조건이 전체일 경우
                   ELSE
                     E.CD_BEEMP END
    )
반응형