如何在CASE语句中使用多个条件

时间:2019-04-03 08:27:29

标签: sql-server tsql

我想在一种情况下使用以下条件,我该怎么做

((LTRIM(RTRIM(AdvertisementAuthorityAfterDateOfPublication.AAADPPapCode)) = (LTRIM(RTRIM(@PapCode)))) AND
(DATEDIFF(DAY,(CONVERT(date,@PubDate,111)),(CONVERT(date,CURRENT_TIMESTAMP,111)))) > (AdvertisementAuthorityAfterDateOfPublication.AAADPAddNoOfDates)
AND
(LTRIM(RTRIM(AdvertisementAuthorityAfterDateOfPublication.AAADPSysOperator))) != (LTRIM(RTRIM(@UserName))))

我尝试以下方法,但出现错误

SELECT CASE
        WHEN ((LTRIM(RTRIM(AdvertisementAuthorityAfterDateOfPublication.AAADPPapCode)) = (LTRIM(RTRIM(@PapCode))))
          AND (DATEDIFF(DAY, (CONVERT(date, @PubDate, 111)), (CONVERT(date, CURRENT_TIMESTAMP, 111)))) > (AdvertisementAuthorityAfterDateOfPublication.AAADPAddNoOfDates)
          AND (LTRIM(RTRIM(AdvertisementAuthorityAfterDateOfPublication.AAADPSysOperator))) != (LTRIM(RTRIM(@UserName))))
          IS NULL THEN 1

   AS ErrorTag;

0 个答案:

没有答案