Date range
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Date range Expand / Collapse
Author
Message
Posted 11/28/2007 10:24:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/28/2007 10:09:46 AM
Posts: 1, Visits: 1
Hi
I want to write a query to get results for only last week, i.e Date between (current_date -7) and current_Date. when i write above syntex it is not working for me.

Can anyone help me?

Thank in advance.
-Nitin


Nitin Ajmeri
Post #9885
Posted 11/28/2007 11:11:02 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 8/26/2008 4:53:36 PM
Posts: 50, Visits: 220
May be the date format or datatype in the column you are comparing to is different. Try casting to same format and data type. You may also try using >= , <= instead of 'between and'.
Post #9888
Posted 11/28/2007 3:15:35 PM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 3/5/2008 9:54:38 AM
Posts: 67, Visits: 147
select * from sys_calendar.calendar where calendar_date between current_date-7 and current_date order by calendar_date

The above query does return rows for me. Check the column that you are using in your where condition.
Post #9896
Posted 11/29/2007 1:52:30 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/25/2008 7:26:06 AM
Posts: 474, Visits: 202
Hi Nitin,
"it's not working for me" is not helpfull at all, at least provide the error code/message.

It's working for me :-)

Dieter
Post #9905
Posted 3/3/2008 5:20:43 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/3/2008 5:19:43 PM
Posts: 8, Visits: 25
I got this from someone in the forum last month as I had the same question.

...
INNER JOIN (Select calendar_date-day_of_week-6 as min_date, calendar_date-day_of_week as max_date
from sys_calendar.calendar where calendar_date = current_date) date_range
ON trans_date between date_range.min_date and date_range.max_date
...


James Clasen
Post #10781
Posted 3/4/2008 9:28:04 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 9/4/2008 4:08:05 PM
Posts: 91, Visits: 117
works for me. Are you sure your table has data for the range given?
Post #10787
Posted 5/16/2008 8:44:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/30/2008 10:31:41 AM
Posts: 4, Visits: 6
I perform a similar query quite often when I want to get data from the first of the month until today's date--and the way I do it is by casting my date column as a date then taking day from current_date-current_date plus one as my first day of the month and then simply current_date for today.

The code example is below:



cast(a.snapshot_date as date) BETWEEN (current_date - EXTRACT(DAY FROM current_date)+1) AND current_date;


So I'm sure this could easily be set to pull the previous week's data by just inserting the code you had for a week ago--i.e. ((current_date -7)).
Post #11471
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 10:51am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 9 queries. Compression Disabled.