Skip to main content
Question

If/Then in a Custom Field Select Statement

  • June 22, 2022
  • 2 replies
  • 172 views

Forum|alt.badge.img+10

I am trying to add field Approved_By_UserId from  views ‘Gen_Led_Vouchers2’ or ‘Voucher’ to as a custom field on ‘Supplier Invoices Analysis’, ‘Multi-Company Invoices Analysis’, and ‘AP Suppler Invoices Analysis’.

Basically if the field is null in gen_led_vouchers2 i can get it from transactions in the hold table.

But I have never seen an IF/Then in a custom field select statement. :-/

Can this be done and does anyone have an example?

 

Thanks

Cindy

 

2 replies

Forum|alt.badge.img+12
  • Hero
  • 217 replies
  • June 22, 2022

Sounds like a use case for COALESCE or NVL -- if one field is null, take the other. You would still have to perform a query to link to both tables, though so that both values could be checked. That might be processor-intensive since it still needs to do all the work.

Oracle doesn't have anything like an IIF() (immediate IF) keyword, but you can read the documentation on DECODE() and CASE expressions for that sort of processing.

Thanks,
Joe Kaufman


EntNadeeL
Hero (Partner)
Forum|alt.badge.img+10
  • Hero (Partner)
  • 182 replies
  • June 23, 2022

Hi

You can create a read only field with SELECT CASE statement.

 

SELECT

(CASE 

WHEN t.field = null THEN ‘output_value1’

WHEN t.field = x THEN ‘output_valu2’

ELSE

‘output_default’

END) Custom_field_output

FROM gen_led_vouchers2 t

I am not sure if this satisfies your requirement. But this is how you write if/else in a select statement. 

 

Thanks

Best Regards

Nadeesha Liyanage