1

我正在编写一个查询,该查询根据名为“USERDATE”的用户定义日期确定要使用的价格。当我运行它时,我得到一个“表达式中的语法错误(缺少运算符)”。我希望选择的价格是稍后在查询中使用的“UNIT_AMT”。

SELECT MDDB.NDC, CARRIER.GROUP_ID, [USERDATE] AS USERDATE, MDDB.CODE, CARRIER.DUR_MU_R, CARRIER.FEE_BR, CARRIER.FEE_GR, CARRIER.AWP_BR, CARRIER.AWP_GR, CARRIER.DUR_MU_M, CARRIER.FEE_BM, CARRIER.FEE_GM, CARRIER.AWP_BM, CARRIER.AWP_GM, MDDB.AWP_UNIT_AMT, 

CASE
WHEN USERDATE >= AWP_EFF_DATE THEN AWP_UNIT_AMT
WHEN USERDATE >= AWP_1ST_OLDEST_EFF_DATE AND USERDATE < AWP_EFF_DATE THEN AWP_1ST_OLDEST_UNIT_AMT
WHEN USERDATE >= AWP_2ND_OLDEST_UNIT_AMT AND USERDATE < AWP_1ST_OLDEST_UNIT_AMT THEN AWP_2ND_OLDEST_UNIT_AMT
WHEN USERDATE >= AWP_3RD_OLDEST_UNIT_AMT AND USERDATE < AWP_2ND_OLDEST_UNIT_AMT THEN AWP_3RD_OLDEST_UNIT_AMT
WHEN USERDATE >= AWP_4TH_OLDEST_UNIT_AMT AND USERDATE < AWP_3RD_OLDEST_UNIT_AMT THEN AWP_4TH_OLDEST_UNIT_AMT
WHEN USERDATE >= AWP_5TH_OLDEST_UNIT_AMT AND USERDATE < AWP_4ST_OLDEST_UNIT_AMT THEN AWP_5TH_OLDEST_UNIT_AMT
ELSE AWP_UNIT_AMT
END AS UNIT_AMT,

((([UNIT_AMT]*[QTY])*((100+[AWP_GR])/100))+[DUR_MU_R]+[FEE_GR]) AS [GR PRICE], 
((([UNIT_AMT]*[QTY])*((100+[AWP_BR])/100))+[DUR_MU_R]+[FEE_BR]) AS [BR PRICE], 
((([UNIT_AMT]*[QTY])*((100+[AWP_GM])/100))+[DUR_MU_M]+[FEE_GM]) AS [GM PRICE], 
((([UNIT_AMT]*[QTY])*((100+[AWP_BM])/100))+[DUR_MU_M]+[FEE_BM]) AS [BM PRICE]
FROM MDDB_MASTER AS MDDB, CARRIER_GROUP AS CARRIER
WHERE (((MDDB.NDC)="41520091574") AND ((CARRIER.GROUP_ID)="709608"));

感谢您的时间和帮助!

4

1 回答 1

2

由于 Access SQL 不支持CASE ... WHEN,因此您可以使用嵌套IIf()表达式。然而,有这么多条件,嵌套IIf()将具有挑战性。在这种情况下,您可能会发现Switch()更易于使用。

Switch(
    USERDATE >= AWP_EFF_DATE, AWP_UNIT_AMT,
    USERDATE >= AWP_1ST_OLDEST_EFF_DATE AND USERDATE < AWP_EFF_DATE, AWP_1ST_OLDEST_UNIT_AMT,
    USERDATE >= AWP_2ND_OLDEST_UNIT_AMT AND USERDATE < AWP_1ST_OLDEST_UNIT_AMT, AWP_2ND_OLDEST_UNIT_AMT,
    USERDATE >= AWP_3RD_OLDEST_UNIT_AMT AND USERDATE < AWP_2ND_OLDEST_UNIT_AMT, AWP_3RD_OLDEST_UNIT_AMT,
    USERDATE >= AWP_4TH_OLDEST_UNIT_AMT AND USERDATE < AWP_3RD_OLDEST_UNIT_AMT, AWP_4TH_OLDEST_UNIT_AMT,
    USERDATE >= AWP_5TH_OLDEST_UNIT_AMT AND USERDATE < AWP_4ST_OLDEST_UNIT_AMT, AWP_5TH_OLDEST_UNIT_AMT,
    True, AWP_UNIT_AMT
) AS UNIT_AMT
于 2013-07-02T17:41:25.930 回答