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
 Update column using variables

Author  Topic 

Addcom
Starting Member

5 Posts

Posted - 2014-07-03 : 16:54:18
Trying to replace a string in a table and it is not working the path can be like \\OM-WD08-1\report\Data.raw. can some advice what is wrong
Thanks

USE Config

DECLARE @OldPath varchar(30), @NewPath varchar(30)

-- Initialize the variable
SET @OldPath ='\\OM-WD08-1\';
SET @NewPath ='\\AA-PC\';

UPDATE AnatomyConfigs
SET Path = REPLACE(Path,@OldPath,@NewPath) WHERE Path IS NOT NULL
AND Path LIKE @OldPath
GO



albert

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-03 : 16:57:24
AND Path LIKE '%' + @OldPath + '%'

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

Addcom
Starting Member

5 Posts

Posted - 2014-07-07 : 04:48:46
Thanks for your solution, it worked as expected
Wondering if the statement "Where Path IS NOT NULL and Path Like '@OldPath' will ever be true?
I might just say "WHERE Path LIKE @OldPath"

albert
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-08 : 12:41:17
Yes definitely modify the where clause to eliminate the unneeded part.

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

- Advertisement -