IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Insert rec or Update specific field of table using file i\p


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Feb 17, 2009 9:27 am
Reply with quote

I have file with key and value for specific column.

I want to insert the records to table from file if not present
and update columns with value in file if key is present in table.

can it be done using db2 load utility or any other solution for such request?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 17, 2009 9:31 am
Reply with quote

Hello,

Read the file. Query the table. If found update. If not found insert.

Is there a value in the file for one column or all of the columns? If there is only a value for one column, you need to decide what values to use for the other columns unless they have been defined with a default value.

You should validate the value(s) in the file before updating or inserting any rows.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Feb 17, 2009 9:40 am
Reply with quote

Quote:

Is there a value in the file for one column or all of the columns?


file has all the columns.


as file has many records reading each record then querying table and then again do insert\update using program would take more time.

I was looking for any option of bulk load or update if available..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 17, 2009 9:50 am
Reply with quote

Hello,

How would that validate the data before doing an insert/update?

Quote:
as file has many records reading each record then querying table and then again do insert\update using program would take more time.
A very bad choice is the choice between ensuring the data is valid over possibly saving a bit of processing time. . .
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Feb 17, 2009 2:06 pm
Reply with quote

You can use multi-insert if your version of DB2 supports it.

Otherwise, write the records to be inserted into another file. Then use load utility to insert them into the table. But the updates has to happen inside the program.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Mar 22, 2011 4:33 pm
Reply with quote

Hi All,

Am stuck up with similar request again, so continueing this thread..

We are going to add new column in table as char 1, This will hold values either Y or N.

There are around 2 million older records in the table (at the time of adding new column) out of which, I want do update 1.8 as flag Y and remaining .2 as value N.

I have those keys in seperate files. This as this is one time activity.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Mar 22, 2011 6:10 pm
Reply with quote

answering to the old question : There is such a SQL verb as MERGE (single row and/or multirow).

for the new question:
Load those keys to a seperate worktable say tab2 with an index on PK
then do
update tab1 set newcol = 'Y'
update tab1 A set newcol = 'N' where exists(select 1 from tab2 B where A.pk1 = B.pk1)

Probably an unload/sort merge /load can do the same,
but how to sort merge adding a field 'Y' when matched, 'N' when not matched, that you have to ask in the sort forum.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Load new table with Old unload - DB2 DB2 6
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top