Link to home
Start Free TrialLog in
Avatar of Gerhardpet
GerhardpetFlag for Canada

asked on

Need help with an query using the IF syntax

Can someone help me with this?

SELECT Format('Paid by:') AS paid_by, terms.terms_descrip AS terms
FROM invchead INNER JOIN terms ON invchead.invchead_terms_id = terms.terms_id;

I need the above query to do this

If terms = ‘Credit Card’ then paid_by and terms  else NULL

The text should look like this if terms = ‘Credit Card’ then “Paid by: Credit Card”
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gerhardpet

ASKER

When I try the query you have suggested against the database both in access and Postgres I get an error

In Postgres I get

ERROR:  column "Credit Card" does not exist
LINE 1: SELECT IIf(terms.terms_descrip="Credit Card", "Paid by: Cred...
                                       ^

********** Error **********

ERROR: column "Credit Card" does not exist
SQL state: 42703
Character: 32
I found that Postgresql does not support an Iif statement. In Access it work with an ODBC connection to postgresql

This works in postgresql

 SELECT CASE WHEN terms.terms_descrip ='Credit Card' then 'Paid by: Credit Card' else NULL end AS paid_by
FROM invchead INNER JOIN terms ON invchead.invchead_terms_id = terms.terms_id;

Thanks for you help!