Question : replace field value with another value using MS TSQL

Hi

I have a Access database with a table called document in it - I also have odbc connection to it from my TSQL tool so I can run sql scripts etc from it. I need to replace a field value in the table called document in a field called file_directory.

Currently I have these typical values (thousands like this!):-

//server1/folder12/newfile.docx
//server1/folder10/someotherfilename.xls

I want to change thses so that the server name is changed ie:-

//server2/folder12/newfile.docx etc. etc.

can this be done through TSQL?

Thanks for your help!

Answer : replace field value with another value using MS TSQL

Replace is only available if used in VB, not in SQL, and yes, as it is executed in Access, the function has to be there to be able to use it. Thus it is no TSQL anymore.

Since you have a very simple replacement here, you can use the mid function:

update document
set file_directory = '//server2/' + mid(file_directory, len('//server1/')+1, 255)
where file_directory like '//server1/*'

The length of 255 chars is arbitrary; if your paths exceed that length, increase it.
Random Solutions  
 
programming4us programming4us