Link to home
Create AccountLog in
Avatar of Lia Nungaray
Lia NungarayFlag for United States of America

asked on

How to use the DECODE function

Hello Experts.

I am using the following query in a Power BI Paginated Report. 


SELECT * FROM FINAL 

WHERE Bill_Type = DECODE((SELECT pBillType FROM PARAMETERS_SECTION),'ALL',Bill_Type,(SELECT pBillType FROM PARAMETERS_SECTION))


I do not understand how the DECODE function works. Can someone explain it to me? Please don't direct me to a site, I rather you explain with your own words, I have looked at several websites and have not been completely helpful. Thanks.

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Lia Nungaray

ASKER

Thanks, that is starting to make some sense. Here's the complete query block:


SELECT * FROM FINAL 

WHERE Revenue_Code = DECODE((SELECT pRevenueCode FROM PARAMETERS_SECTION),'ALL',Revenue_Code,(SELECT pRevenueCode FROM PARAMETERS_SECTION))


 I need to update the last select to something like the following statement, but it is not recognizing pRevenueCode when I use this select:


WHERE Revenue_Code = DECODE((SELECT pRevenueCode FROM PARAMETERS_SECTION),'ALL',Revenue_Code,(SELECT LOB_PARAM.VALUE FROM TABLE(STRTOK_SPLIT_TO_TABLE(pRevenueCode, ',')) AS LOB_PARAM))


Does this look right to you?





Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>> Does this look right to you?

From your new question it seems that you found a flaw in the statement above?
Multiple values from the STRTOK_SPLIT_TO_TABLE need the 'IN' clause not an '='.