How to fire an update query using datastage job?

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

qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

How to fire an update query using datastage job?

Post 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
Sreenivasulu
Premium Member
Premium Member
Posts: 892
Joined: Thu Oct 16, 2003 5:18 am

Post by Sreenivasulu »

Use the property 'user-defined sql'. Here you can write any DML statement
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

If it is a one-off activity, why not run a stand-alone query ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What database? Which stage type?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post by qutesanju »

yep,
using ODBC i can erite a SQL -update query but is there an alternative way to write it using datastage jobs?
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post 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? ...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
arunpramanik
Participant
Posts: 63
Joined: Fri Jun 22, 2007 7:27 am
Location: Kolkata

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
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

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post by qutesanju »

I think using below fuction i can achieve this
change
ereplace OR
convert OR
Left OR
Right
arunpramanik
Participant
Posts: 63
Joined: Fri Jun 22, 2007 7:27 am
Location: Kolkata

Post 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
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post 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
arunpramanik
Participant
Posts: 63
Joined: Fri Jun 22, 2007 7:27 am
Location: Kolkata

Post by arunpramanik »

qutesanju wrote: input query -->transformer-->database table
Can you share the stage used and the Update statement used in stage
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply