Archives of the TeradataForum
Message Posted: Fri, 09 Feb 2007 @ 19:23:45 GMT
In your example, since selecting from dual with no where clause always returns one row, rownum - 1 will be 0 and the whole add_months business isn't needed.
select date; select current_timestamp;
Depending on whether or not you need the time component.
The general answer to rownum is to add row_number() over (order by <something or other>) and wrap another query around that. Not that you'd ever need to do this, but something like
select top 10 add_months(calendar_date, -(rownum-1) ) from (select row_number() over (order by calendar_date) rownum, t.calendar_date from date_dim t) x
(This query will fail if it happens to return rows where the add_months calculation is outside the range of valid dates.)
By the way, if you're going to use add_months, be aware that Teradata handles the last day of the month differently than Oracle:
SELECT add_months('28-feb-2007',1) from dual; 31-Mar-2007
select add_months('2007-02-28',1); 03/28/2007
|Copyright 2016 - All Rights Reserved|
|Last Modified: 28 Jun 2020|