MS ACCESS的SWITCH CASE

时间:2018-05-09 10:03:13

标签: sql ms-access switch-statement

我想问一下ms访问中的选择案例。从我得到的是db2 任何人都可以帮助更改MS Access 2000的SQL

SELECT DISTINCT 

    CASE WHEN STORECODE='JPAT' THEN

        CASE WHEN PARTNO LIKE 'A%' THEN 

            ITEMNAME||'(NIV-'||SECTIONNO||')'

            WHEN PARTNO LIKE 'STSB%' THEN 

        ITEMNAME||' (NIV-'||SECTIONNO||')'

    ELSE

        ITEMNAME||'('||PARTNO||'-'||SECTIONNO||')'

    END

ELSE

ITEMNAME||'('||PARTNO||'-'||SECTIONNO||')'

END

    AS INPUTTEXT,

        IDX||':'||PARTNO||':'||BATCHNO||':'||ITEMTYPECODE||':'||TOOLTYPECODE||':'||ITEMCATEGORYCODE||':'||MATERIALTYPECODE||':'||SECTIONNO AS INPUTVAL

from ITEM  where idx > 0   and (storecode)='JPAT'

感谢

1 个答案:

答案 0 :(得分:1)

在MS Access中,这看起来像:

SELECT DISTINCT 
       IIF(PARTNO LIKE 'A*', ITEMNAME & "(NIV-" & SECTIONNO & ")"
           IIF(PARTNO LIKE "STSB*", ITEMNAME & " (NIV-" & SECTIONNO & ")"
               ITEMNAME & "(" & PARTNO & "-" & SECTIONNO & ")"
              )
          ) AS INPUTTEXT,
    (IDX & ":" & PARTNO & ":" & BATCHNO & ":" & ITEMTYPECODE & ":" &
     TOOLTYPECODE & ":"& ITEMCATEGORYCODE & ":" & MATERIALTYPECODE &
      ":" & SECTIONNO
    ) AS INPUTVAL
FROM ITEM 
WHERE idx > 0 AND storecode = "JPAT";

注意:

  • storecode = 'JPAT'中不需要比较SELECT,因为它位于WHERE
  • MS Access中的字符串分隔符为",而非'
  • MS Access中的字符串连接运算符为&
  • MS Access中LIKE中的通配符为*
  • MS Access不支持CASE。我发现IIF()足以满足这种情况(双关语)。