Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2002
    Posts
    84

    Question Unanswered: Copy a column from one table to another

    Is there any DB2 command that can copy one column in a table
    to another table?

    Thanks.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Copy a column from one table to another

    It will be easy to answer your question if you could give more details of what you want ..

    Cheers

    Sathyaram

    Originally posted by qxz
    Is there any DB2 command that can copy one column in a table
    to another table?

    Thanks.

  3. #3
    Join Date
    Apr 2002
    Posts
    84

    Copy a column from one table to another

    For example, If I want to copy the whole Column Customer_ID
    from Customer table to Member_ID in the Member table, can I
    do so from command line?

    Thanks.

  4. #4
    Join Date
    Nov 2001
    Location
    Finland, Kirkkonummi
    Posts
    17
    Hi,

    If the column does not exist in target table use ALTER TABLE to add it.

    Then copy the data using SQL:

    INSERT INTO Member (Member_ID) SELECT Customer_ID FROM Customer

    Vesku

  5. #5
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Copy a column from one table to another

    I can't think of a way of doing this from the command line directly ... Anybody else has an idea?

    Alternatively, you can do an EXPORT/IMPORT INSERT_UPDATE or create a view.

    HTH

    Sathyaram

    Originally posted by qxz
    For example, If I want to copy the whole Column Customer_ID
    from Customer table to Member_ID in the Member table, can I
    do so from command line?

    Thanks.

  6. #6
    Join Date
    Apr 2002
    Posts
    84

    Copy a column from one table to another

    Hi,

    Thanks. That is what I wanted. I created a table defining the other
    fields with default values, and then executed the SQL from command
    line.


    Originally posted by vesku
    Hi,

    If the column does not exist in target table use ALTER TABLE to add it.

    Then copy the data using SQL:

    INSERT INTO Member (Member_ID) SELECT Customer_ID FROM Customer

    Vesku

  7. #7
    Join Date
    Jul 2011
    Posts
    1

    use join

    Quote Originally Posted by qxz View Post
    Hi,

    Thanks. That is what I wanted. I created a table defining the other
    fields with default values, and then executed the SQL from command
    line.
    that did not work for me
    what worked is given below

    update member
    set member_id = b.column_id
    from member a (nolock),
    coloumn b (nolock)
    where a.sno collate database_default = b.sno

    cheers!

    Varun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •