SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Replacing some Names in a SQl column but not all
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

raindear
Yak Posting Veteran

64 Posts

Posted - 12/02/2013 :  14:16:55  Show Profile  Reply with Quote
Hi

I have a SQL table with 5000 rows in it. Some of the other SQL columns have different values but if I wanted to swap say 500 of the rows would it be something like

UPDATE Coupins
SET Name='test1,test2,test3'
WHERE Name='test4,test5,test6';

I need basically to swap the Name value of these without affecting any other values.

tkizer
Almighty SQL Goddess

USA
37133 Posts

Posted - 12/02/2013 :  14:19:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
Yes. You specify which rows to update by providing the appropriate WHERE clause. To see if your query is correct, run this first:

select *
from Coupins
WHERE Name='test4,test5,test6';

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37133 Posts

Posted - 12/02/2013 :  14:20:22  Show Profile  Visit tkizer's Homepage  Reply with Quote
Why do you have comma separated values in the Name column? Shouldn't it be normalized instead?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 12/02/2013 :  14:59:51  Show Profile  Reply with Quote
I'm wondering if their objective is to change all 'test1' values to 'test4' and change all 'test2' values to 'test5' etc...

Be One with the Optimizer
TG
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37133 Posts

Posted - 12/02/2013 :  15:44:52  Show Profile  Visit tkizer's Homepage  Reply with Quote
quote:
Originally posted by TG

I'm wondering if their objective is to change all 'test1' values to 'test4' and change all 'test2' values to 'test5' etc...




Oh! Yeah maybe.

raindear, please clarify.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000