Not familiar with using if, then and else in my querie - assistance needed.

I have a piece of code that someone gave me for a Teradata report I am working on but have been unable to reach them for a question. I have never used an if, then and else in my queries so I am not sure how to apply this code. Would it go in the Select statement or the Where Clause and is the format correct or does it need ( )

IF AP_CLAIM_2.FROM_OCR_YN = ‘N’
AND
AP_CLAIM.EDI_INFO IS NOT NULL
THEN EDI, ELSE PAPER
Culwatrnca11Data AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

awking00Information Technology SpecialistCommented:
SELECT CASE WHEN AP_CLAIM2.FROM_OCR_YN = 'N' AND AP_CLAIM.EDI_INFO IS NOT NULL THEN EDI ELSE PAPER END
0
Culwatrnca11Data AnalystAuthor Commented:
awking00,
Get an error..    5628: column EDI not found in ap_claim_2 or ap_claim

SELECT
CASE WHEN AP_CLAIM_2.FROM_OCR_YN = 'N' AND AP_CLAIM.EDI_INFO IS NOT NULL THEN EDI ELSE PAPER END

FROM AP_Claim
LEFT OUTER JOIN ap_claim_2 ON ap_claim.claim_id = ap_claim_2.claim_id
0
awking00Information Technology SpecialistCommented:
I was just copying from what you wrote. The basic syntax for your case statement is "when [conditions] are true then expression1 else expression2" where expression can be a column value or a literal, etc. I don't know your data so I don't know if a field named EDI (or PAPER) exists anywhere in your tables or perhaps you meant for them to be literals which would require they be enclosed in quotes. What is it you want returned when if/case conditions are true and when they are false?
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Culwatrnca11Data AnalystAuthor Commented:
awking00,

THanks for explaining.  basically i want a column that would return EDI or PAPER in the column. Column name could be  EDI_ Paper
0
awking00Information Technology SpecialistCommented:
Then make it a literal (i.e. in quotes) and name the column -
SELECT
 CASE WHEN AP_CLAIM_2.FROM_OCR_YN = 'N' AND AP_CLAIM.EDI_INFO IS NOT NULL THEN 'EDI'
 ELSE 'PAPER' END as EDI_Paper
 FROM AP_Claim
 LEFT OUTER JOIN ap_claim_2 ON ap_claim.claim_id = ap_claim_2.claim_id
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Culwatrnca11Data AnalystAuthor Commented:
Thank you this worked..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Teradata

From novice to tech pro — start learning today.