请求将DB2 CASE语句转换为MS Access 2000兼容的SQL查询语句
Hey there! Let's tackle converting your DB2 SQL to work with MS Access 2000. The main adjustments we need to make are replacing DB2's CASE WHEN logic with Access's IIF function and swapping the string concatenation operator || for Access's & (since || acts as a logical OR in Access SQL, not a string joiner).
Here's the converted query that should work seamlessly in Access 2000:
SELECT DISTINCT IIF(STORECODE='JPAT', IIF(PARTNO LIKE 'A%', ITEMNAME & '(NIV-' & SECTIONNO & ')', IIF(PARTNO LIKE 'STSB%', ITEMNAME & ' (NIV-' & SECTIONNO & ')', ITEMNAME & '(' & PARTNO & '-' & SECTIONNO & ')' ) ), ITEMNAME & '(' & PARTNO & '-' & SECTIONNO & ')' ) AS INPUTTEXT, IDX & ':' & PARTNO & ':' & BATCHNO & ':' & ITEMTYPECODE & ':' & TOOLTYPECODE & ':' & ITEMCATEGORYCODE & ':' & MATERIALTYPECODE & ':' & SECTIONNO AS INPUTVAL FROM ITEM WHERE idx > 0 AND STORECODE='JPAT'
Key Changes Breakdown:
CASE WHEN→ NestedIIF: Access 2000 doesn't support standard SQLCASEstatements, so we useIIF(condition, result_if_true, result_if_false)instead. Each layer of your originalCASElogic translates to a nestedIIFcall.- String Concatenation Fix: Replaced every
||with&– this is the correct operator for joining strings in Access SQL. - Cleaned Up WHERE Clause: Removed unnecessary parentheses around
storecodeto make the query more readable (the original syntax would still work, but this is cleaner).
If you hit any snags testing this, feel free to follow up!
内容的提问来源于stack exchange,提问作者Irwan Ahmad
相关产品推荐
相关产品推荐

