Using a Formula instead of value to populate a field in DB2

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

Post Reply
ggarze
Premium Member
Premium Member
Posts: 78
Joined: Tue Oct 11, 2005 9:37 am

Using a Formula instead of value to populate a field in DB2

Post by ggarze »

When updating a DB2 table using the DB2/UDB stage I'm trying to get the database to calculate the field value based on the columns I pass it but it's treating what I pass it as a string not a calculation for DB2 to execute. For example: If I run this statement in Command Center it works and the numeric value of the calculation is displayed on the table properly.
UPDATE TABLE
SET EP_NUMERATOR=SCDLR_EFF_HRS + SCDLR_UNPAID_BREAK_HRS
WHERE FIELDA = '01'

Note:Both SCDLR_EFF_HRS and SCDLR_UNPAID_BREAK_HRS are fields on TABLE.

But when I run this in Datastage
UPDATE TABLE
SET EP_NUMERATOR=?
WHERE FIELDA = '01'

Note: '?' is resolved from the incoming file which has the calculation SCDLR_EFF_HRS + SCDLR_UNPAID_BREAK_HRS (no quotes either in the file)

The error I get is that 'EP_NUMERATOR has been truncated to SCDLR_EFF_HR'

So it looks like DataStage is trying just to pass this equation in as a String into the field which is defined as a decimal.

Is what I'm trying possible in DataStage and I'mjustmissing something or does DataStage need an actual value to update?

Thanks
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Do you mean you want the formula to be dynamically substituted ?

If it is always addition, why not do in datastage and pass the result ?

You need to provide more information.
ggarze
Premium Member
Premium Member
Posts: 78
Joined: Tue Oct 11, 2005 9:37 am

Post by ggarze »

[quote="Sainath.Srinivasan"]Do you mean you want the formula to be dynamically substituted ?

If it is always addition, why not do in datastage and pass the result ?

You need to provide more information. ...[/quote]

Yes, I want the formula substituted. The formula is not always the same and can change per row and per run. Ultimately each row will have 5 seperate buckets all containing different formulas. Right now I'm just trying to get one to work.
ggarze
Premium Member
Premium Member
Posts: 78
Joined: Tue Oct 11, 2005 9:37 am

Post by ggarze »

So the next thing I tried is making the update User Defined SQL and replaced the '?' with an actual formula as if I was writing it in command center, not taking it from the input file. It worked that way. So, for some reason the stage deosn't like when the formula is coming in from a source.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure, because when it is 'coming in from the source' it is just a string value you want to load into that field.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ggarze
Premium Member
Premium Member
Posts: 78
Joined: Tue Oct 11, 2005 9:37 am

Post by ggarze »

Yeah t he field is a string, but in the file there are no quotation marks around it so when it replaces the '?' In the update statement it shoul looks just as it did when I hard coded the formula in it and it worked. Right?
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Maybe you can construct a case statement and pass a pointer value to indication the expression to be evaluated.
Post Reply