Quantcast
Channel: SCN : All Content - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 4013

How to fill a table column with a value from other column of same table

$
0
0

Hi Experts,

 

Now this is something tricky and few possible things are not working out.

 

SCENARIO :

 

I have a table SFE_EXP_BODS_F. Suppose there are 5 columns in table :

 

1. DIVISION_NAME (varchar)

2. SPECIALITY_NAME (varchar)

3. CALDATE (date)

4. TIMES_EXPOSED (int)

5. PY_TIMES_EXPOSED (int) --> to be filled

 

CALDATE contains the value from 1 APR 2014 to 31 Mar 2016. (in blocks of month like 2014-04-01, 2014-05-01)

 

First four columns are coming from previous transformation but PY_TIMES_EXPOSED is getting calculated here in this query transform (via New output column).

 

LOGIC to be implemented for PY_TIMES_EXPOSED :

This column should get the same value as TIMES_EXPOSED column exactly 1 year back.

 

This means if a record is coming in this query transform with CALDATE = 2015-04-01, PY_TIMES_EXPOSED should get the value from TIMES_EXPOSED column of this table when CALDATE was 2014-04-01 and rest all fields value = present values of record.

 

If a record comes with CALDATE < 2015-04-01, then PY_TIMES_EXPOSED should be NULL because the data is from 01 APR 2014 onwards.

 

 

IMPLEMENTATION :

 

I tried devising a logic for this scenario and here's the mapping I used for PY_TIMES_EXPOSED in query transform :

 

ifthenelse(CALDATE > '2015-03-31',

sql('DRL_ORACLE_Prod', 'SELECT TIMES_EXPOSED from SFE_EXP_F_BODS where CALDATE = \'[add_months(Q_LOOKUP2.CALDATE, -12)]\'

AND DIVISION_NAME = \'[Q_LOOKUP2.DIVISION_NAME]\'

AND SFE_BRAND = \'[Q_LOOKUP2.SFE_BRAND]\'

AND SPECIALITY_NAME = \'[Q_LOOKUP2.SPECIALITY_NAME]\'

AND HQ_CODE = \'[Q_LOOKUP2.HQ_CODE]\'

AND CLASSIFICATION = \'[Q_LOOKUP2.CLASSIFICATION]\''), NULL)

 

Few other fields seen in above sql operation are just other dimension fields which needs to be matched to fetch TIMES_EXPOSED.

 

This mapping is not giving any error in validation and should have worked as per me but it is not working when the execution control reaches this query transform. 0 records are sent to target, which is after this query transform and job errors out. Error screen is attached. There's no ODBC connectivity issue.

 

 

Any workaround to achieve this functionality??? Please help me. It's very urgent.

 

Thanks a ton as always! Arun SasiDirk Venken


Viewing all articles
Browse latest Browse all 4013

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>