Is there an easy way to copy data from one column to another within the same table?

  • Hi all,

    Is there any easy way to do it in T-SQL statement?

     

    Thanks!

    Betty

  • If the columns are in the same table:

    Update MyTable

    set MyNewColumn = MyOldColumn

    if the columns are in different tables:

    Update MyNewTable

    set MyNewColumn = (select MyOldColumn from MyOldTable where some criteria )

    SQL = Scarcely Qualifies as a Language

  • Carl,

    That works (same table data). Thank you so much.

    You know what I tried as follow before I saw your post.

    update myTable set myNewColumn=(Select myOldColumn from myTable where ...)

    it didn't work says that subquery have multiple values.

    Betty

  • update a set a.MyNewColumn = b.MyOldColumn from table1 a , table2 b where a.<keyfield> = b.<keyfield>

  • I'm in a picky mood today

    Don't use this old legacy syntax:

    update a set a.MyNewColumn = b.MyOldColumn from table1 a , table2 b where a.<keyfield> = b.<keyfield>

    Use ANSI syntax instead:

    update a set a.MyNewColumn = b.MyOldColumn from table1 a JOIN table2 b ON a.<keyfield> = b.<keyfield>

    /Kenneth

  • Is there an easy way to do this in sybase ISQL???

  • Have you tried the ANSI syntax in Sybase?

    /Kenneth

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply