我需要在 case 语句中为 sqr 中的 sql 语句的 select 部分使用日期变量,并不断收到错误。当我使用 getdate() 函数进行比较但不适用于我的变量时,它工作正常。请帮忙。包含代码。
BEGIN-SELECT
DBO.GET_XLAT_DESC(A.TPD_PARISH,'TPD_PARISH') "DESCR" &LABEL_DESCR (+2,4)
COUNT(1) "CNT" &ENT_CNT (,23) ! total entities matching base criteria
COUNT(CASE WHEN B.ATTACH_TYPE_CD = 'PHC' AND B.EXPIRATION_DATE >= getdate()
THEN 1 END) "HEALTH_PST" &H_PAST (,34)
COUNT(CASE WHEN B.ATTACH_TYPE_CD = 'PHC' AND B.EXPIRATION_DATE >= $curr_dte
THEN 1 END) "HEALTH_CUR" &H_CURR (,44)
COUNT(CASE WHEN B.ATTACH_TYPE_CD = 'PHC' AND B.EXPIRATION_DATE >=
DATEADD($START_DATE,'MONTH',-1) THEN 1 END) "HEALTH_FTR" &H_FUTR
let #region_total = #region_total + #ent_total
PRINT #ent_total (, 235) EDIT 999,999 BOLD
FROM PS_TPD_ENTITY A LEFT JOIN PS_TPD_ENT_ATTACH B ON A.TPD_ENTITY =
B.TPD_ENTITY
WHERE $TPD_REPORT_TYPE = 'P'
AND (RTRIM(LTRIM(UPPER(A.TPD_ENT_STATUS))) = $TPD_ENT_STATUS OR
$TPD_ENT_STATUS ='')
AND (RTRIM(LTRIM(UPPER(A.TPD_ENTITY_TYPE))) = $TPD_ENTITY_TYPE OR
$TPD_ENTITY_TYPE ='')
AND (RTRIM(LTRIM(UPPER(A.REGION))) = $REGION OR $REGION ='')
AND (RTRIM(LTRIM(UPPER(A.TPD_PARISH))) = $TPD_PARISH OR $TPD_PARISH ='')
GROUP BY A.TPD_PARISH
order BY DESCR