sql server 2012 - How do I update a value in SQL by looking up another table using that value? -
i have table superkittens column name 'kittenid'
this value number, such 12345.
i have table called kittens 2 columns, kittenid , kittennewid
i want update superkittens , change kittenid kittennewid, using table kittens values.
i thought might work, apparently it's not valid:
update superkittens sk set sk.kittenid = (select kittennewid kittens k k.kittenid = sk.kittenid)
any ideas?
edit: error got it's invalid sql:
msg 102, level 15, state 1, line 1 incorrect syntax near 'sk'.
you may try this:
update superkittens sk set sk.kittenid = k.kittennewid kittens k inner join on sk.kittenid = k.kittenid
or may try merge option this:
merge superkittens sk using kittens k on sk.kittenid = k.kittenid when matched update set sk.kittenid = k.kittennewid;
Comments
Post a Comment