SQL QueriesSQL Tips

Replacing a Part of a String with Another String

By 08/12/2022 December 3rd, 2024 No Comments

Problem Statement:

While managing a large- scale database,  sometimes we might need to replace a string’s substring with another. There is always a option of deleting the record and adding it with new value. That’s the first thing that pops into everyone’s mind. But SQL provides another efficient way to do that.


Code Snippet:

Select [Name],[GroupName],REPLACE(‘sales and Marketing’, ‘Sales and’, ‘Strategic ‘) as NewValue
FROM [AdventureWorks].[HumanResources].[Department] Where [GroupName] = ‘sales and Marketing’

Code Output:

Leave a Reply