Reputation:
I have logic which i need to convert it to decode statement
My logic is below :
if emptr =='SBCS':
empcd=empvar
else:
if empcal <> depcal and empid in ('SSC','HSC'):
empcd = (emp_sal/avgsal) * empad
elif empcal <> depcal and empid not in ('SSC','HSC'):
empcd = emp_del
else:
empcd = emp_dev
Tried myself to write the logic in expression
IIF ( emptr ='SBCS' , empvar , IIF(empcal <> depcal,IIF(empcal <> depcal and empid in ('SSC','HSC'),(emp_sal/avgsal) * empad,emp_del),emp_dev))
I have written DECODE logic , but not sure right or wrong
DECODE(TRUE,
empid ='SBCS', empvar,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and (empid <> 'SSC' or empid <> 'HSC'), emp_del,
emp_dev
)
Feel free to share your logic if the DECODE
logic is not right
Upvotes: 0
Views: 350
Reputation: 3353
I believe I've already answered this exact question there. Was there anything wrong with the below code I provided?
DECODE(TRUE,
empid ='SBCS', v_employee_code_number,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and empid <> 'SSC' and empid <> 'HSC', emp_del,
emp_dev
)
Upvotes: 0
Reputation: 7407
You can refer to below expression. Pls remove comments (--comments
) if needed.
iif (emptr ='SBCS', empvar,
iif( -- first else if part
empcal <> depcal and IN (empid, 'SSC','HSC'), (emp_sal/avgsal) * empad,
iif ( --second elif
empcal <> depcal and NOT IN (empid, 'SSC','HSC') , emp_del,
emp_dev -- last else
)
)
)
I can see your expression and can see some issue with 3rd or condition. in case of NOT IN, or doesnt work. I changed your decode so you can use code below but pls check it before using it.
DECODE(TRUE,
empid ='SBCS', empvar,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and (empid <> 'SSC' and empid <> 'HSC'), emp_del,
emp_dev
)
Upvotes: 1