Excel IF Statement in Teradata SQL 13.0

Teradata Applications

Excel IF Statement in Teradata SQL 13.0

Hello All,

I'm a intermediate end user in Teradata 13.0 and am starting to get into a little more complex SQL Statements. So I may be coming here asking what may be simple questions to you all. I would like to make an EXCEL IF Statement in Teradata SQL.

Example:

IF( paid amt > 0, copay + coins + ded, 0.00) OPP is the column name

Thanks


Accepted Solutions
Apprentice

Re: Excel IF Statement in Teradata SQL 13.0

Hi,

No problem. Where it goes depends on what you want it to do for you.

The most common use of the case expression is to generate another column in your answer set, in which case (no pun intended!) it needs to go into the 'select list'. Something like:

SEL clm, adj_nbr, charge, allow, etc
sum(bill_amt * .10) "10%Charge"

,(case
when paid_amt > 0 then copay + coins + ded
else 0.00
end) as OPP

etc.
FROM Db.Claims   WHERE **bleep**  AND **bleep**
GROUP BY **bleep**, ORDER BY **bleep**

If that doesn't work then please post the error code and message.

Cheers,

Dave

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
1 ACCEPTED SOLUTION
4 REPLIES
Apprentice

Re: Excel IF Statement in Teradata SQL 13.0

Hi,

 

'IF' => SQL 'CASE'

 

(case

when paid_amt > 0 then copay + coins + ded

else 0.00

end) as OPP

 

Where paid_amt, copay ,coins , ded and OPP are all column names.

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com

Re: Excel IF Statement in Teradata SQL 13.0

Thank you Dave.

Dave, I have an addition to the question I did not include.

My complete statement is:

SEL clm, adj_nbr, charge, allow, etc

sum(bill_amt * .10) "10%Charge"

etc.

FROM Db.Claims   WHERE **bleep**  AND **bleep**

GROUP BY **bleep**, ORDER BY **bleep**

 

The IF STATEMENT is entered where?

 

I am trying in the select, after the FROM and WHERE; fails

 

One may think I should know that, but does not.

Thanks again for your help.

 

 

Apprentice

Re: Excel IF Statement in Teradata SQL 13.0

Hi,

No problem. Where it goes depends on what you want it to do for you.

The most common use of the case expression is to generate another column in your answer set, in which case (no pun intended!) it needs to go into the 'select list'. Something like:

SEL clm, adj_nbr, charge, allow, etc
sum(bill_amt * .10) "10%Charge"

,(case
when paid_amt > 0 then copay + coins + ded
else 0.00
end) as OPP

etc.
FROM Db.Claims   WHERE **bleep**  AND **bleep**
GROUP BY **bleep**, ORDER BY **bleep**

If that doesn't work then please post the error code and message.

Cheers,

Dave

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com

Re: Excel IF Statement in Teradata SQL 13.0

YES!!!

Dave you'e the Man Smiley Very Happy