Update every row Column_3 = Column_2?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssap1197
    New Member
    • May 2007
    • 1

    #1

    Update every row Column_3 = Column_2?

    I need a quick hand updating every row in a table.

    I know you need to do a loop and pass Unique ID info on to the update statement. I just don't know how to do that in SQL.

    Below is what I want to do to each row in the table.

    Table = XYZ
    Column_1 = ID(Unique)
    Column_2 = X
    Column_3 = Z

    UPDATE XYZ
    SET Column_3 = Column_2
  • rharvieuxsql
    New Member
    • Nov 2006
    • 9

    #2
    Can you give an example of the output you're looking for? What you have works. See example:

    --create sample table
    create table XYZ (
    Column_1 int,
    Column_2 varchar (100),
    Column_3 varchar (100)
    )

    --create sample data
    insert XYZ values (1, 'a','b')
    insert XYZ values (2, 'b','b')
    insert XYZ values (3, 'c','b')
    insert XYZ values (4, 'd','b')

    --lets update
    update xyz
    SET Column_3 = Column_2

    --results
    select * from xyz

    Column1 Column2 Column3
    1 a a
    2 b b
    3 c c
    4 d d

    Comment

    Working...