How can I update a table variable with a join

  • Hi,

    Is there a way to perform an update on a table variable using a join to a actual table?

    This is the update i'm trying to run:

    update @temp
    set @temp.desc = table1.desc
    from @temp, table1
    where @temp.id = table1.id

    I've tried using an alias for the table variable instead of the variable name, but I can't seem to get that to work either.

    Any ideas?

     

  • I think this is the correct syntax (not tested, though):

    update s

    set s.desc = t.desc

    from @temp s inner join table1 t

    on s.id = t.id

  • Hi,

    Genius!

    I've tested it and it works.

    Thanks!

  • No way - experience is what it takes

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

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