Solved

If Statement With Teradata Query

Posted on 2010-09-13
2
5,073 Views
Last Modified: 2013-11-11
I need to run a specific query if the date is the ninth of the month.  A different query would need to be run if the date is any other date except the ninth.  I wanted to please ask for the syntax to do this with Teradata.

Something like this is what I need (using MS SQL syntax):
IF ( day(getdate()) = 9)
Begin Select * From Table End
Else
Begin Select *From AlternativeTable End
0
Comment
Question by:jjrr007
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
Comment Utility
jjrr007,

I was hoping someone more qualified in Teradata would have picked this up, but I see you have been waiting several days without assistance.  If you are still in need of help, I can offer up the little I was able to find that may help.

Current Date == CURRENT_TIMESTAMP

One method for getting day is extract(day from CURRENT_TIMESTAMP)
-- http://www.teradataforum.com/l030515a.htm

Only information I can find on if is Bteq.If
-- http://forums.teradata.com/forum/analytics/if-and-else-condition-in-bteq


Anyway, my lack of Teradata skills aside, a thought I had that should work in general SQL is to use a UNION approach.
(the only catch or downside is that the columns must be same -- you could always just use placeholders for those that are not valid for each of the queries)

SELECT col1, col2, col3, col4, null as col5, null as col6
FROM TableFor9th
WHERE EXTRACT(DAY from CURRENT_TIMESTAMP) = 9
UNION ALL
SELECT col1, col2, null as col3, null as col4, col5, col6
FROM AlternativeTable
WHERE EXTRACT(DAY from CURRENT_TIMESTAMP) <> 9

If this kind of solution will work for you, it functions well since each portion of the UNION will only show when the other doesn't so you are guaranteed it is one or the other.

Regards,

Kevin
0
 
LVL 1

Author Closing Comment

by:jjrr007
Comment Utility
Clever idea. Thanks
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now