Page 1 of 2

How to fire an update query using datastage job?

Posted: Tue Aug 03, 2010 1:27 am
by qutesanju
I have few records in a table as shown below ,but due to business rules
I want to update below id 202BILGN16 to 202BILGN12
rest all other rows will be as it is

using a query I can get below recods to update
System Plan Id
P1 102 202BILGN16
P1 102 202BILGN16
P1 102 202BILGN16
P2 103 202BILGN15
P2 103 202BILGN15
P2 103 202BILGN15

but where should I write an update constraint in order to update 202BILGN16 to 202BILGN12

Posted: Tue Aug 03, 2010 2:04 am
by Sreenivasulu
Use the property 'user-defined sql'. Here you can write any DML statement

Posted: Tue Aug 03, 2010 3:12 am
by Sainath.Srinivasan
If it is a one-off activity, why not run a stand-alone query ?

Posted: Tue Aug 03, 2010 3:17 am
by ray.wurlod
What database? Which stage type?

Posted: Tue Aug 03, 2010 3:22 am
by qutesanju
yep,
using ODBC i can erite a SQL -update query but is there an alternative way to write it using datastage jobs?

Posted: Tue Aug 03, 2010 3:24 am
by qutesanju
Database is SQL SERVER
but i m thinking what logic can be implemented for this?
Also this is not one time activity otherwise i would have fired SQL statement for this(using an update query)
ray.wurlod wrote:What database? Which stage type? ...

Posted: Tue Aug 03, 2010 6:19 am
by chulett
Since generated SQL can't bind the same column twice, include it twice in your link (old and new values) then use user-defined SQL to do the actual update in the target stage.

Posted: Tue Aug 03, 2010 7:09 am
by arunpramanik
What are the keys for the update?


I will prefer to use Store procedure, as I get quite confuse with positional parameters and the way columns should be place in input stream for this type of update while using ODBC

Posted: Tue Aug 03, 2010 3:30 pm
by ray.wurlod
Any column marked as Key in the Columns grid can (should, must) be used in the WHERE clause.

Does not the ODBC stage allow you to generate UPDATE statement?

Posted: Tue Aug 03, 2010 4:25 pm
by chulett
It does but not one they could actually use, seeing as how that one column essentially needs to be both a key and a non-key.

Posted: Wed Aug 04, 2010 12:30 am
by qutesanju
I think using below fuction i can achieve this
change
ereplace OR
convert OR
Left OR
Right

Posted: Wed Aug 04, 2010 2:26 am
by arunpramanik
qutesanju wrote:I think using below fuction i can achieve this
change
ereplace OR
convert OR
Left OR
Right
based on your requirement the User Define query should look like

Code: Select all

update  tablexyz set key3=? where key1=? and key2=? and key3=?
and this statement should be such that it can be parse by SQL engine, so any use of DS function will not work.

now if you have in input column
key1, key2,key3,newkey3

I think, and if I am not wrong, the key3 in the set statement will always take the third field from input stream, not the 4th field which you want to have. and If I am wrong, You can try this, and let us know if you have succeeded then post here

Posted: Wed Aug 04, 2010 3:33 am
by qutesanju
I achieved it using

Change(columnName, "16", "12")
because I want to change 202BILGN16 to 202BILGN12

here is flow for my job
input query -->transformer-->seq file
after applying Change(columnName, "16", "12")
I checked seq file i found expected changes was there

I'm trying same now on database by changing flow as
input query -->transformer-->database table

Posted: Wed Aug 04, 2010 4:07 am
by arunpramanik
qutesanju wrote: input query -->transformer-->database table
Can you share the stage used and the Update statement used in stage

Posted: Wed Aug 04, 2010 5:48 am
by chulett
Your solution has already been posted here - twice now - first by myself and then again by arunpramanik. Read and apply that advice. The only thing we've had to guess on are your actual key fields but I think it's a pretty good guess. :wink: