how to get Max(DATE) using transformer

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

how to get Max(DATE) using transformer

Post by pxraja »

Hi all,
hash
I am using ODBC-->TRF---> ODBC

i want to take maxium date for lookup

how can i get in transformer for every records i want only the max dated recor

inlink.field01 inlink.field02
jkdkal 2007/12/12
jkdkal 2008/01/01

I want to take record to ouput column

outlink.field01 outlink.field01
jkdkal 2008/01/01
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sort by field01 then by field02 (descending) prior to the Transformer stage and use stage variables to detect a change in field01. Constrain the output to those rows where you detect a change in field01.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

Post by pxraja »

Hi Ray,

Thanks for your suggestion,

will RowProcCompareWithPreviousValue work for DATE column
in oracle database.

suggestions are welcome

Thanks in Advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

This is a DataStage function so it will only work within DataStage (in no sense will it work "in Oracle database"). It still relies on sorted data to work properly.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

Post by pxraja »

Hi all,

I want to select the first row as a updated one and reject the other rows, for example

inlink.field01 inlink.field02
jkdkal 2007/12/12
jkdkal 2008/01/01
jkdkal 2006/01/01
fkdajj 2005/05/04
fkdajj 2008/04/08
fkdajj 2008/08/23


I want to take record to ouput column as follows

outlink.field01 outlink.field01
jkdkal 2008/01/01
fkdajj 2008/08/23

I can use sort stage for rearranging the columns, as ray quoted " first by field01 and field02(descending).

how to use stage variable to allow only the first row

any ideas or workarround are welcomed

Thanks in advance
syeed
Participant
Posts: 19
Joined: Fri Jan 19, 2007 12:35 am
Location: bangalore

Re: how to get Max(DATE) using transformer

Post by syeed »

Hi,

Map the value like this

outlink.field01 ==> StageVar1
if StageVar1=StageVar2 then 'R' else 'P' StageChkVar
outlink.field01 ==> StageVar2

In Transformer Constraints, u can have condition as StageChkVar='P'

Other Simple Way would be have a remove duplicate stage Sort data based on first by field01 and field02(descending) and Remove duplicate key as field01 with Retain=First Record.

Hope this will help you.

Thanks.
Syed
---------
Wait and Watch
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

There's no 'Remove Duplicates' stage in Server. Well, there is but it's called the Transformer. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No-one on this thread claimed that there was a Remove Duplicates stage in server jobs. :?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: how to get Max(DATE) using transformer

Post by chulett »

Server forum, Server post, PX advise. Hence the comment.
syeed wrote:Other Simple Way would be have a remove duplicate stage Sort data based on first by field01 and field02(descending) and Remove duplicate key as field01 with Retain=First Record.
-craig

"You can never have too many knives" -- Logan Nine Fingers
battaliou
Participant
Posts: 155
Joined: Mon Feb 24, 2003 7:28 am
Location: London
Contact:

Post by battaliou »

You can aggregate your sorted data on the key and choose "last" option for your date. This will function the same as a remove duplicate stage.
3NF: Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key. So help me Codd.
pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

Post by pxraja »

Hi all,

Thanks for your suggestion,

but I am using Inlink.field0, Inlink.field1 as varchar in oracle database and Outlink.field1 as number and Outlink.field2 as Timestamp

while i am using Iconv(Inlink.field1,'D-YMD[4,2,2]') or Oconv(Iconv(Inlink.field1,'D-YMD[4,2,2]'),'DQ4')

the Outlink.field1 is empty or NULL While it is pass without any of Iconv or Oconv it's working fine. I donot get why this response is occuring.
The job runs successfully without any warnings

Please clarify this professionals
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Since your date is in the form YYYY/MM/DD there is no need to convert to internal format. The nulls or empties are a separate issue.
pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

Post by pxraja »

Hi all,

Can any one tell me why it's showing null field, whenever I do conversion on that particular field.

i.e., on Inlink.field01 as mentioned earlier.

I could not able to get quarters of that field.
pxraja
Participant
Posts: 142
Joined: Fri Mar 14, 2008 10:22 am

Post by pxraja »

Hi all,

Can any one tell me why it's showing null field, whenever I do conversion on that particular field.

i.e., on Inlink.field01 as mentioned earlier.

I could not able to get quarters of that field.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Outlink will only be NULL if the input is NULL
Post Reply