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
 General SQL Server Forums
 New to SQL Server Programming
 swapping the values in two feilds

Author  Topic 

sam_1
Starting Member

3 Posts

Posted - 2010-12-08 : 17:59:31

Newbie to SQL hoping someone can help.

I have a 200 rows of information where i have to swap the value in two feilds.

Feild 1 "Street" Feild 2 "City"

i need to swap the values in all 200 rows where datestamp is greater than 07/07/2010 as street name is in the city feild and visa versa.

what would the update query look like for this?

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2010-12-08 : 18:16:05
Something like this:

UPDATE YourTable
SET Street = City, City = Street
WHERE datestamp > '7/7/2010'


Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

sam_1
Starting Member

3 Posts

Posted - 2010-12-08 : 18:31:40
thanks for the quick reply i will try this tomorrow and report back.

Many thanks,
Sam
Go to Top of Page

sam_1
Starting Member

3 Posts

Posted - 2010-12-09 : 17:13:26
Much appreachated all worked a treat. a happy boss!

thanks,
Sam
Go to Top of Page
   

- Advertisement -