Gregory Bond <gnb (AT) itga (DOT) com.au> wrote
Quote:
Consider this:
select 1 as oldid, 2 as id into #tmp;
update #tmp set id=oldid, oldid=0;
Is it guaranteed that id will be non-zero? I.e. is it guaranteed that
the order of assignments in an update matches the order they are
written in? |
The order of assignments doesn't matter when it comes to
column values. The values on the RHS are taken from the
original state of the table.
If you did this:
select 1 as oldid, 2 as id into #tmp;
update #tmp set id = oldid, oldid = id
select * from #tmp
you should get id = 1 oldid = 2
The rules are different when variables are involved.
It is best not to rely on placement in that case - instead
write two update statements in the order you want the
updates to occur.
-bret