Unix Technical Forum

Multiple insert from previous select

This is a discussion on Multiple insert from previous select within the DB2 forums, part of the Database Server Software category; --> Hi, I need to do following, if there is any automated process let me know. 1.excute Select on the ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 10:47 AM
Basu
 
Posts: n/a
Default Multiple insert from previous select

Hi,
I need to do following, if there is any automated process let me know.

1.excute Select on the table (eg, TableA)
2. Insert value to a table with values returned in step 1 with
updating only one column.

for instance selcect dept, year, catg from tablea where dept = 80

it may return 40 rows with different category.

Now we want to insert those 40 rows for dept 81, rest remail same.

we DB2 7 MVS version. Presently we do it manually.

Any help appreciated. Thanks Basu
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 10:47 AM
Rhino
 
Posts: n/a
Default Re: Multiple insert from previous select

]""Basu" <basusm@yahoo.com> wrote in message
news:7cd67dce.0306301003.56e39801@posting.google.c om...
> Hi,
> I need to do following, if there is any automated process let me know.
>
> 1.excute Select on the table (eg, TableA)
> 2. Insert value to a table with values returned in step 1 with
> updating only one column.
>
> for instance selcect dept, year, catg from tablea where dept = 80
>
> it may return 40 rows with different category.
>
> Now we want to insert those 40 rows for dept 81, rest remail same.
>
> we DB2 7 MVS version. Presently we do it manually.
>

Thank you for telling us your DB2 Version; a surprising number of people
post to this newsgroup and don't tell us. That makes it very hard to answer
the question since the answer often depends on the exact version of DB2 and
the OS.

With respect to your question, a trigger is probably what you want. With a
trigger, an event in one table can cause an event in another table. For
example, you could set up a trigger so that adding rows to Table A would
cause rows to be inserted into Table B. You could have another trigger
insert rows in Table B whenever a row in Table A changed. And so on.

Please note that this would become an entirely automated process. You would
not have to remember to do the Select and the Insert every day (or however
often you do it now.)

Consult the DB2 manuals, particularly the Application Programming and SQL
Guide for the concepts and the SQL Reference for the details of the syntax.

Your challenge will be to rethink what you are doing a little so that you
realize what event needs to trigger the insert in the second table.


Rhino


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 10:48 AM
sharpe@us.ibm.com
 
Posts: n/a
Default Re: Multiple insert from previous select

Do you mean something like:
insert into tableb(dept,year,catg)
select dept+1,year,catg
from tablea
where dept=80
;


Basu wrote:

>Hi,
>I need to do following, if there is any automated process let me know.
>
>1.excute Select on the table (eg, TableA)
>2. Insert value to a table with values returned in step 1 with
>updating only one column.
>
>for instance selcect dept, year, catg from tablea where dept = 80
>
>it may return 40 rows with different category.
>
>Now we want to insert those 40 rows for dept 81, rest remail same.
>
>we DB2 7 MVS version. Presently we do it manually.
>
>Any help appreciated. Thanks Basu
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com