t-sql 2012 replace part of value in a field with a different value

  • In a sql server 2012 database. I want to replace part of a value in the column called 'text' that is referring to one url link and replace the value with a new url link. This change needs to happen since the url (link) has changed in production recently.

    The value that needs to be replaced is in the column listed below called 'stringtorepalce' with the new url link of 'https://dd1.org/app/letter.aspx'.

    **Note the 'stringtoreplace' column had to be determined since the link in production has changed several times in the past 10 years.

    SELECT text,

    ,PATINDEX('%https://%',text) as startlocation

    ,PATINDEX('%/letter.aspx%',text) as endlocation

    ,substring(text,PATINDEX('%https://%',text),PATINDEX('%/letter.aspx%',text) - PATINDEX('%https://%',text)) as stringtoreplace

    FROM [dd1].[dbo].[Contact]

    where text like '%spr.org%'

    and text like '%/letter.aspx%'

    and datetimestamp >= '2018-08-01 00:00:00.00'

    order by datetimestamp desc

    Basically the column called 'text' needs to be updated. Thus can you show me the sql on how to 'replace part of a value in the column called 'text' that is referring to one url link and replace the value with a new url link?

  • Not sure if I got it correctly.... If you know sequence of characters you replacing use REPLACE() function. If you need to replace at certain positions, use STUFF() function.

    --Vadim R.

  • Can you post some sample data and the results you expect please? Make sure you're posting the data as formatted text (like you should be when pasting code). You can paste formatted text by click the Insert/edit code sample button and pasting the text there.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • solved the problem

  • wendy elizabeth wrote:

    solved the problem

    What was the solution, out of interest?

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply