Access/jet Equivalent Of Oracle's Decode
Solution 1:
The closest analogy is the SWITCH()
function e.g.
Oracle:
SELECT supplier_name,
decode(supplier_id, 10000, 'IBM',
10001, 'Microsoft',
10002, 'Hewlett Packard',
'Gateway') resultFROM suppliers;
Access Database Engine
SELECT supplier_name,
SWITCH(supplier_id = 10000, 'IBM',
supplier_id = 10001, 'Microsoft',
supplier_id = 10002, 'Hewlett Packard',
TRUE, 'Gateway') AS result
FROM suppliers;
Note that with the SWITCH()
function you have to supply the full predicate each time, so you are not restricted to using just supplier_id. For the default value, use a predicate that is obvious to the human reader that it is TRUE e.g. 1 = 1
or indeed simply TRUE
:)
Something that may not be obvious is that the logic in the SWITCH()
function doesn't short circuit, meaning that every expression in the function must be able to be evaluated without error. If you require logic to short circuit then you will need to use nested IIF()
functions.
Solution 2:
You can try with IIF. See this stackoverflow question.
Solution 3:
I think it might compare to switch or choose.
Switch(expr-1, value-1[, expr-2, value-2 … [, expr-n,value-n]])
-- http://office.microsoft.com/en-us/access/HA012289181033.aspx
Choose(index, choice-1[, choice-2, ... [, choice-n]])
-- http://msdn.microsoft.com/en-us/library/aa262690%28VS.60%29.aspx
Solution 4:
You can use the SWITCH
function:
LABEL: Switch(
[TABLE_NAME]![COL_NAME]='VAL1';'NEW_VAL1';
[TABLE_NAME]![COL_NAME]='VAL2';'NEW_VAL2';
)
Note semicolons and not commas.
The example above works in queries in MS Access 2010.
Post a Comment for "Access/jet Equivalent Of Oracle's Decode"