#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    1
    Rep Power
    0

    Copy rows and change 1 value


    How would I copy entire rows within a table and change one value?

    insert into user
    (user_id,account_id,user_type_cd,name,e_mail_addr,login_failure_cnt,admin_user,primary_user)
    select * from pnet_user where account_id='DDD111'

    but now I want to change DDD111 to DDD222 on the inserted entries.

    Thanks for any help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    222
    Rep Power
    15
    try this:
    Code:
    insert into user
    (user_id,account_id,user_type_cd,name,e_mail_addr,login_failure_cnt,admin_user,primary_user)
    select user_id, 'DDD222', user_type_cd, name, e_mail_addr, login_failure_cnt, admin_user, primary_user) from pnet_user where account_id='DDD111'
    basically list each field that you want to retrieve as opposed to using * ... then include the value you want changed as part of your select.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0
    That was exactly what I needed, too; thanks very much indeed!

IMN logo majestic logo threadwatch logo seochat tools logo