Solved

If Statement With Teradata Query

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

Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

689 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