Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

If Statement With Teradata Query

Posted on 2010-09-13
2
Medium Priority
?
5,859 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 2000 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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