Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 switch two fields

Author  Topic 

codism
Starting Member

11 Posts

Posted - 2007-03-06 : 11:28:01
I wrote a script to switch two fields for certain rows:
quote:

declare @tmp int
update my_table
set
@tmp = field1,
field1 = field2,
field2 = @tmp
where my_condition = true


The above script works fine while I am worrying it is only correct when the execution order for the three assignment statements is guaranteed. I do not want to use a temporary table because of performance concerns. Can any one give me the confidence by any suggestion or any document that makes the script always correct?

Thanks in advance.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-06 : 11:30:10
[code]update my_table
set field1 = field2,
field2 = field1
where my_condition = true
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

codism
Starting Member

11 Posts

Posted - 2007-03-06 : 12:10:58
You code works! Can you point me the article talking about the principle?
Go to Top of Page
   

- Advertisement -