logic required

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
hargun
Participant
Posts: 188
Joined: Mon May 16, 2011 7:41 pm
Location: United States

logic required

Post by hargun »

hi,

I am using the db2 stage to extract the using the query to fetch the records from column using the logic expression
YEAR(TO_DATE(AUC_SALE_DATE,'yyyy-mm-dd')) || '-' || WEEK(TO_DATE(AUC_SALE_DATE,'yyyy-mm-dd'))

the results from this query coming as
2012-5
2012-44
2011-47
2012-18
2013-32

I want the last two numbers of first field like 2012-05 instead of 2012-5 .

the design of job is


db2 stage................xfm...................seqfile

in tried with following way in transformer

right((0:AUC_SALE_DATE),2) but not getting the right result like 2012-50 can you please help me about this.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: logic required

Post by chulett »

hargun wrote:I want the last two numbers of first field like 2012-05 instead of 2012-5.
Doesn't DB2 have a "to char" function?
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Try adding quotes around the zero inside your Right() function.
Choose a job you love, and you will never have to work a day in your life. - Confucius
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can't just use 'right' in the job as you want weeks not days. Look into the YearFromDate and YearweekFromDate functions.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ssnegi
Participant
Posts: 138
Joined: Thu Nov 15, 2007 4:17 am
Location: Sydney, Australia

Post by ssnegi »

DSFIELD1 : YEAR(TO_DATE(AUC_SALE_DATE,'yyyy-mm-dd'))
DSFIELD2 : WEEK(TO_DATE(AUC_SALE_DATE,'yyyy-mm-dd'))

Transformer Stage :

Column Derivation
DSFIELD1 : '-' : Str('0',2-len(DSFIELD2)):DSFIELD2
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ssnegi wrote:Column Derivation
DSFIELD1 : '-' : Str('0',2-len(DSFIELD2)):DSFIELD2
Overkill. Since WEEK will never have more than two digits, the original formulation will work.

Code: Select all

DSFIELD1 : "-" : Right("0" : DSFIELD2, 2)
The expression "0" : DSFIELD2 can only ever return two or three characters, since WEEK must be between 1 and 53.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jerome_rajan
Premium Member
Premium Member
Posts: 376
Joined: Sat Jan 07, 2012 12:25 pm
Location: Piscataway

Post by jerome_rajan »

Which version of Db2 do you have? It's been more than a year since I last worked with Db2 but I do remember using either 'CHAR()' or 'TO_CHAR()' in a way very similar to Oracle.

(Edit)
Found this -
http://www-01.ibm.com/support/knowledge ... 007108.htm
Jerome
Data Integration Consultant at AWS
Connect With Me On LinkedIn

Life is really simple, but we insist on making it complicated.
Post Reply