Si M...
Thanks for the direction. Probably a little late, but this is a sample of the code I was trying to convert from Oracle to Teradata:
SELECT /*+ PARALLEL(t) USE_HASH(t, a) */
t.tran_code
, a.agrmt_id
, (FIRST_VALUE(a.agrmt_id) OVER(PARTITION BY SUBSTR(a.agrmt_src_id, 1, 10) ORDER BY a.agrmt_type_id)) base_agrmt_id
FROM tl_transactions t
, agreements a
WHERE t.agrmt_ext_id = SUBSTR(a.agrmt_src_id, 1, 10)
AND a.src_system_id = '10'
AND t.load_date = '19-FEB-2004'
AND NVL(t.dollar_amount, 0) != 0
Because of the specifics of my need, I was getting a "Ordered Analytical Functions can not be nested". I needed to use a "SUBSTR" in the "PARTIIONED BY" clause and Teradata did not like both the "SUBSTR" and the "QUALIFY RANK". I was trying the code below:
SELECT t.tran_code
, a.agrmt_id
, aa.agrmt_id AS base_agrmt_id
, RANK() OVER (PARTITION BY SUBSTR(aa.agrmt_src_id, 1, 10) ORDER BY aa.agrmt_type_id) as first_agrmt_id
FROM staging.tl_transactions t
, salesmi.agreements a
, salesmi.agreements aa
WHERE t.agrmt_ext_id = SUBSTR(a.agrmt_src_id, 1, 10)
AND t.agrmt_ext_id = SUBSTR(aa.agrmt_src_id, 1, 10)
AND a.src_system_id = 10
AND t.load_date = '2004-02-19'
AND ZEROIFNULL (t.dollar_amount) <> 0
QUALIFY RANK (first_agrmt_id) = 1
I kept working with it and came up with the following. Not sure about efficiency yet, but it provides the right results.
SELECT t.tran_code
, a.agrmt_id
, aa.base_agrmt_id
FROM staging.tl_transactions t
, salesmi.agreements a
, (SELECT a1.agrmt_id AS base_agrmt_id
,a1.agrmt_src_id
,RANK() OVER (PARTITION BY SUBSTR(a1.agrmt_src_id, 1, 10) ORDER BY a1.agrmt_type_id) as first_agreement
FROM salesmi.agreements a1
WHERE a1.src_system_id = 10) as aa
WHERE t.agrmt_ext_id = SUBSTR(a.agrmt_src_id, 1, 10)
AND t.agrmt_ext_id = SUBSTR(aa.agrmt_src_id, 1, 10)
AND aa.first_agreement = 1
AND a.src_system_id = 10
AND t.load_date = '2004-02-19'
AND ZEROIFNULL (t.dollar_amount) <> 0
If there is a better way, please let me know.
Again, Thanks for the help.
gsdcrazy