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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| ]""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 |
| ||||
| 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 > |