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
 Replacing some Names in a SQl column but not all

Author  Topic 

raindear
Yak Posting Veteran

64 Posts

Posted - 2013-12-02 : 14:16:55
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

38200 Posts

Posted - 2013-12-02 : 14:19:54
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

38200 Posts

Posted - 2013-12-02 : 14:20:22
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
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-12-02 : 14:59:51
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

38200 Posts

Posted - 2013-12-02 : 15:44:52
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
   

- Advertisement -