Solved

If Statement With Teradata Query

Posted on 2010-09-13
2
5,426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33697877
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
ID: 33698262
Clever idea. Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

696 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