Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 363469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:20:44+00:00 2026-05-12T13:20:44+00:00

I have a select statement that I want to use as the basis for

  • 0

I have a select statement that I want to use as the basis for adding more rows to a table.
The new rows will have some columns modified and the original row will have to be altered also.

This is a once off occurance and the DB can be taken offline if that helps.

Any ideas?

Thanks,
Joe

=================

Description Update

MBANK Table

       |MID  |MAGN|MAAID|MTYPEOT|        MAVAILS|MUSER|MTS
OLD    |65   |   9|    3|      2|              A|NAME |20090909
NEW    |65   |  10|    0|      2|              A|NAME |20090910
CHANGE |SAME |  +1| TO 0|   SAME|New = A Old = O|SAME |TIMESTAMP

This will have to be done for approx 4000 records on a select.

select * from MDSTD.MBANK where MTYPEOT = ‘2’ and MAVAILS = ‘A’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:20:44+00:00Added an answer on May 12, 2026 at 1:20 pm

    DrJokepu solution is ok, but that depends if what you call “Changes” in your question, is fixed. I.e.: are you always going to change +1 for the 2nd column? Or are those changes “dynamic” in a way you have to decide upon runtime which changes you’re going to apply?

    There are in DB2 and any other SQL different constructs (like the insert into in DB2) or SELECT INTO for MS-SQL that will allow you to construct a set of queries.

    If I am not mistaken, you want to do this:

    1. Insert some values into a table that come from a select (what you call “old”)
    2. Create another set of records (like the “old” ones) but modify their values.

    Or maybe you just want to do number 2.

    Number 1 is easy, as Dr.Jokepu already showed you:

    INSERT INTO <table> (values) SELECT "values" FROM <anotherTable>;
    

    Number 2 you can always do in the same query, adding the changes as you select:

    INSERT INTO MDSTD.MBANK ( MID, MAGN, MAAID, MTYPEOT, MAVAILS, MUSER, MTS)
    SELECT 
          MID 
         ,MAGN + 1
         ,0 as MAAID
         ,MTYPEOT
         ,'A' as MAVAILS
         ,MUSER
         ,GETDATE() 
    FROM mdstd.mbank 
    WHERE MTYPEOT = '2' and MAVAILS = 'A'
    

    (note the GETDATE() is a MS-SQL function, I don’t remember the exact function for DB/2 at this moment).

    One question remains, in your example you mentioned:

    “New = A Old = O”

    If Old changes to “O”, then you really want to change the original row? the answer to this question depends upon the exact task you want to accomplish, which still isn’t clear for me.

    If you want to duplicate the rows and change the “copies” or copy them and change both sets (old and new) but using different rules.

    UPDATE
    After rereading your post I understand you want to do this:

    1. Duplicate a set of records (effectively copying them) but modifying their values.
    2. Modify the original set of records before you duplicated them

    If that is the case, I don’t think you can do it in “two” queries, because you’ll have no way to know what is the old row and what is the new one if you have already duplicated.

    A valid option is to create a temporary table, copy the rows there (modify them as the “new ones) with the query I’ve provided). Then in the original table execute an “update” (using the same WHERE CLAUSE to make sure you’re modifying the same rows), update the “old” values with whatever you want to update and finally insert the new ones back into the original table (what we called “new”) that are already modified.
    Finally, drop the temp table.

    Phew!

    Sounds weird, but unless we’re talking about zillions of records every minute, this ought to be a kind of fast operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to following SQL Statement that I want to conver to LINQ Select
I want to execute one mysql statement where I have a select that is
I have a select statement that returns a table full of SELECT statements (It
I have a table: ComputerID, UserID, LoginDate I need a select statement that returns:
So I have this select statement that I am trying to make more responsive.
I have A Script that has a Select statement to go to multiple sub
I have a query that makes several calls within a SELECT statement to a
I have created a procedure and used the below statement inside that . select
I have a select statement and in a couple of the fields, I want
I have a select statement, retrieve about 1000 record I want to modify it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.