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?
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.

 
awking00Commented:
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
 
awking00Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
 
awking00Commented:
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 ConnectWise

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.