SQL Question.
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.


SQL Question. Expand / Collapse
Author
Message
Posted 10/26/2009 1:53:10 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/26/2009 2:51:50 PM
Posts: 4, Visits: 13

User would like a view built on table that would return a record for each date between eff_bgn_dt and eff_end_dt having invry_qty constant for each group of records.

Table Structure:
CREATE TABLE PRODUCT.RTL_INVRY_RDF_EOD
(
Loc_Id SMALLINT NOT NULL ,
Wd_Cd INTEGER NOT NULL ,
Eff_Bgn_Dt DATE NOT NULL
FORMAT 'YYYY-MM-DD' ,
Eff_End_Dt DATE NOT NULL
FORMAT 'YYYY-MM-DD' ,
Invry_Qty DECIMAL(9,2) NOT NULL ,
Adt_Id INTEGER NOT NULL
)
PRIMARY INDEX RTL_INVRY_RDF_EOD_NUPI
(
Loc_Id,
Wd_Cd
)
;


sel loc_id,wd_cd,eff_bgn_dt,eff_end_dt,invry_qty
from dsb.rtl_invry order by 3 ;
Loc_Id Wd_Cd Eff_Bgn_Dt Eff_End_Dt Invry_Qty
2 200,041 2009-10-13 2009-10-17 35.00
2 200,041 2009-10-18 2009-10-19 33.00
2 200,041 2009-10-20 2009-10-20 30.00
2 200,041 2009-10-21 2009-10-21 21.00
2 200,041 2009-10-22 9999-12-31 33.00


View:
example:
sel loc_id,wd_cd,eff_bgn_dt ,invry_qty
from dsb.rtl_invry order by 3 ;
Loc_Id Wd_Cd Eff_Bgn_Dt Invry_Qty
2 200041 2009-10-13 35
2 200041 2009-10-14 35
2 200041 2009-10-15 35
2 200041 2009-10-16 35
2 200041 2009-10-17 35
2 200041 2009-10-18 33
2 200041 2009-10-19 33
2 200041 2009-10-20 30
2 200041 2009-10-21 21
2 200041 2009-10-22 33

RDBMS 12.00.02.17


Any Ideas appreciated.
Thanks, R Glass




Post #17159
Posted 10/27/2009 1:24:35 AM


Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: Yesterday @ 12:42:08 AM
Posts: 74, Visits: 32
Hi,
The simplest solution I see is to Inner Join your current table to a Table containing all dates as columns with a BETWEEN clause for the eff_bgn_date and eff_end_date. There is usually a DATE datamart in every DWH implementation for such purposes. Get in touch if you need further help.

Sample
SELECT ..,..,..,..
FROM TAB A
INNER JOIN {DATE TABLE} B
ON B.Date_of_day BETWEEN A.eff_bgn_date AND A.eff_end_date;


Strive to success.

Arun.

Post #17162
Posted 10/27/2009 7:59:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/28/2009 12:33:17 PM
Posts: 2, Visits: 17
HI there ,



The following query will provide exact results for your requirement.



sel loc_id,wd_cd,calendar_date,eff_bgn_dt ,invry_qty

from dsb.rtl_invry,

sys_calendar

where calendar_date between eff_bgn_dt AND eff_end_dt

order by 3 ;





Eswar
Teradata consultant
Post #17169
« 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:06pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.078. 6 queries. Compression Disabled.