表达式时的MS Access SQL情况

时间:2019-04-17 14:01:28

标签: tsql ms-access case-when

我正在尝试将代码块从SQL Server Management Studio转换为Access数据库,而我的Case When表达式遇到了一些麻烦。

下面的情况下我缺少什么,因此它与MS Access查询兼容?

Case WHEN E.MemberStartDate <= "2018-01-01 AND E.MemberEndDate >= "2018-12-31" 
THEN "" 
WHEN "2018-01-01" <= E.MemberEndDate AND "2018-01-31" >= 
E.MemberStartDate THEN "X" ELSE "" END AS Cov1Jan

2 个答案:

答案 0 :(得分:1)

尝试使用 IIf octothorpes (#):

IIf(E.MemberStartDate <= #2018/01/01 AND E.MemberEndDate >= #2018/12/31#, 
    Null,
    IIf(#2018/01/01# <= E.MemberEndDate AND #2018/01/31# >= E.MemberStartDate, 
        "X", 
        Null)) AS Cov1Jan

答案 1 :(得分:0)

您丢失了MS-Access不支持case的信息。所以:

switch(E.MemberStartDate <= "2018-01-01 AND E.MemberEndDate >= "2018-12-31", "", 
       "2018-01-01" <= E.MemberEndDate AND "2018-01-31" >= 
E.MemberStartDate, "X"
       1=1, "") AS Cov1Jan