April 6, 2009 at 11:58 am
I have a table in SQLServer 2005 that has 250 rows. One of the columns contains values that are directory paths for reports. These directory paths include the name of the server. Example:
ServerName\volume1\Folder1\subfolder1\ReportName1
ServerName\volume1\Folder1\subfolder1\ReportName2
Servername\volume1\Folder1\subfolder1\ReportName3
etc.
The server name will be the same on every row.
How can I change just the server name on every row of the table?
Chris from Cincinnati
April 6, 2009 at 12:08 pm
You can use the REPLACE function
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 6, 2009 at 12:11 pm
You can use the replace function as long as you want to replace all occurances of the server name.
Update Table
Set Col = Replace(Col,'ServerName','NewServerName')
If you just want to replace the first few characters, you can build a new string using the substring function. What I am getting at here is that if for example you had...
ServerName\data\ReportServerNameSometing
It would now be...
NewServerName\data\ReportNewServerNameSometing
As long as you are ok with that, the Replace should be fine.
April 6, 2009 at 12:53 pm
Using the REPLACE function worked perfectly! Thanks much! Especially for the detailed examples.
Chris
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply