Skip to content
Advertisement

Find a string inside a string and update in SQL Server

I have a table like this :

I need to replace the string inside the tag c24 tag..

Excepted output: I need to replace the letter ‘G’ to be replaced with ‘T’ like this inside c24 tag – HT0010001 and all the rest should be same unchanged…

What I tired:

Advertisement

Answer

If the code always begins with ‘H’, then I imagine it’s easier to just have ‘<c24>H’ be part of the string to replace, but then add it back again:

If it doesn’t, then I’d say you’re on the right track with charindex and substring. But use patindex instead, and update fbank directly, don’t put the search term into any variable. If you’re trying to split up your logic into parts, consider cross apply:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement