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
Solved

If Statement With Teradata Query

Posted on 2010-09-13
2
5,341 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
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…

861 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