copy rows within a table

  • I would like to take row in a table and update other existing rows so they copy all columns of this row exactly, (except the PK of course).

    Is there a short way of doing this without lots of variables and update, (SET x = @x) statements?

     

  • UPDATE MyTable

    SET ColA = A.ColA,

    ColB = A.ColB,

    ....

    FROM MyTable A

    WHERE A.ColX = @Value

    _____________
    Code for TallyGenerator

  • try this one :

    declare @colA varchar(50),@colB varchar(50),@colC varchar(50)

      select @colA=colA,@colB=colB,@colC=colC from tblX

       where id = '1' -- this is the one that you want to get the data from

    update tblX

    set colA=@colA,colB=@colB,colC=@colC

    where id <> '1'

     

Viewing 3 posts - 1 through 2 (of 2 total)

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