dbTalk Databases Forums  

using a sql statement to do a string replace

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss using a sql statement to do a string replace in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bj daniels
 
Posts: n/a

Default using a sql statement to do a string replace - 08-20-2003 , 02:09 PM






I am not certain which group to post this to - sorry if this is the wrong
group:

I have a table that holds the location of various media and such (mostly
images). One field is the Media name, the other is the URL in the form
http://myServer.gunnery.org/media/pic1 for example. we are about to move
all the media to a new location (new server). the paths will remain the
same except for the server name.

Is there an update statement that will let me go through the table an
replace myServer with newServer in all the URLs (and leave the rest of the
URL alone). So the link above would become
http://newServer.gunnery.org/media/pic1. I know how I would do it with VB,
but I am not as familar with all the tricks in SQL.

thanks

bj daniels
danielsb (AT) gunnery (DOT) org



Reply With Quote
  #2  
Old   
Keith Kratochvil
 
Posts: n/a

Default Re: using a sql statement to do a string replace - 08-20-2003 , 02:16 PM






You should be able to use the REPLACE function. This select statement should show you that it works as expected:

SELECT REPLACE(MediaName, 'myServer.gunnery', 'newserver.gunnery') FROM YourTable


After verifying that the select gives you the expected result, run the following update to update the data within the table:

--UPDATE YourTable SET MediaName = REPLACE(MediaName, 'myServer.gunnery', 'newserver.gunnery')
--SELECT @@rowcount AS RowsUpdated

--
Keith

"bj daniels" <danielsb (AT) gunnery (DOT) org> wrote

Quote:
I am not certain which group to post this to - sorry if this is the wrong
group:

I have a table that holds the location of various media and such (mostly
images). One field is the Media name, the other is the URL in the form
http://myServer.gunnery.org/media/pic1 for example. we are about to move
all the media to a new location (new server). the paths will remain the
same except for the server name.

Is there an update statement that will let me go through the table an
replace myServer with newServer in all the URLs (and leave the rest of the
URL alone). So the link above would become
http://newServer.gunnery.org/media/pic1. I know how I would do it with VB,
but I am not as familar with all the tricks in SQL.

thanks

bj daniels
danielsb (AT) gunnery (DOT) org



Reply With Quote
  #3  
Old   
bj daniels
 
Posts: n/a

Default Re: using a sql statement to do a string replace - 08-20-2003 , 02:19 PM



Looks Perfect - thanks!


"Aaron Bertrand - MVP" <aaron (AT) TRASHaspfaq (DOT) com> wrote

Quote:
UPDATE table SET mediaName = REPLACE(mediaName, '//myServer',
'//newServer')
WHERE CHARINDEX('//myServer', mediaName) > 0


"bj daniels" <danielsb (AT) gunnery (DOT) org> wrote in message
news:eNjDE50ZDHA.1620 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
I am not certain which group to post this to - sorry if this is the
wrong
group:

I have a table that holds the location of various media and such (mostly
images). One field is the Media name, the other is the URL in the form
http://myServer.gunnery.org/media/pic1 for example. we are about to
move
all the media to a new location (new server). the paths will remain the
same except for the server name.

Is there an update statement that will let me go through the table an
replace myServer with newServer in all the URLs (and leave the rest of
the
URL alone). So the link above would become
http://newServer.gunnery.org/media/pic1. I know how I would do it with
VB,
but I am not as familar with all the tricks in SQL.

thanks

bj daniels
danielsb (AT) gunnery (DOT) org







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.