Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    10

    Unanswered: Copy rows into the same table with new values

    Current
    TABLE 1
    Col1 Col2 Col3 Col4 Col5 Col6
    657 BB 0 10/08/2011 09:05 User
    658 BB 1 10/08/2011 09:05 User
    659 BB 2 10/08/2011 09:06 User
    660 BB 3 10/08/2011 09:06 User
    661 BB 8 10/08/2011 09:06 User
    662 BB 9 10/08/2011 09:06 User
    663 BB 10 10/08/2011 09:06 User
    664 BB 11 10/08/2011 09:06 User


    I want to copy the above rows into the same table with replaced col2 values as CC. Also note that Col1 is autonumber so i would like the new set of rows autonumbered.

    DESIRED RESULT
    TABLE


    Col1 Col2 Col3 Col4 Col5 Col6
    657 BB 0 10/08/2011 09:05 User
    658 BB 1 10/08/2011 09:05 User
    659 BB 2 10/08/2011 09:06 User
    660 BB 3 10/08/2011 09:06 User
    661 BB 8 10/08/2011 09:06 User
    662 BB 9 10/08/2011 09:06 User
    663 BB 10 10/08/2011 09:06 User
    664 BB 11 10/08/2011 09:06 User
    num CC 0 10/08/2011 09:05 User
    num CC 1 10/08/2011 09:05 User
    num CC 2 10/08/2011 09:06 User
    num CC 3 10/08/2011 09:06 User
    num CC 8 10/08/2011 09:06 User
    num CC 9 10/08/2011 09:06 User
    num CC 10 10/08/2011 09:06 User
    num CC 11 10/08/2011 09:06 User


    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    INSERT
      INTO table1
         ( Col2
         , Col3
         , Col4
         , Col5
         , Col6 )
    SELECT 'CC'
         , Col3
         , Col4
         , Col5
         , Col6
      FROM table1
     WHERE Col1 BETWEEN 657 AND 664
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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