September 13, 2020 at 7:41 pm
I have a varchar(130) field called exportpath. I want to replace the word devserver with prodserver where ever it finds that string
in the field. Can it be ran with a select first to see and verify the output before doing the update?
data:
\\devserver\exporta\filename.txt
\\netloc\exporta\devserver\filename.txt
After update:
\\prodserver\exporta\filename.txt
\\netloc\exporta\prodserver\filename.txt
Thanks.
September 13, 2020 at 8:44 pm
easy - a select with a where with a update with a replace and a where clause.
what have you tried so far and what issues did you get ? this is basic sql.
September 13, 2020 at 11:36 pm
not sure why I thought it was diffcult
update tblset exportfilename = REPLACE(exportfilename , 'devserver', 'prodserver')
where exportfilename like (%devserver%)
Thanks sorry..
September 13, 2020 at 11:37 pm
update tbl
set exportfilename = REPLACE(exportfilename , 'devserver', 'prodserver')
where exportfilename like (%devserver%)
September 21, 2020 at 1:30 pm
Thanks to TSQL's support of updates with from clauses, I frequently write new or ad-hoc updates in this format (at least in development) to make testing easy:
update tblset
set
-- select *,
exportfilename = REPLACE(exportfilename , 'devserver', 'prodserver')
from tblset
where exportfilename like '%devserver%';
Just execute from select forward when you want to see the update. Execute the whole statement to actually update once effect is validated.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply