Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Insert rec or Update specific field of table using file i\p
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

Site Director


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

PostPosted: Tue Feb 17, 2009 9:31 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Feb 17, 2009 9:50 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us