Replacing a specific substring with another substring in a SQL stored procedure string

I have the following requirement. I pass "ABC DEF" as a parameter to the @MyString command in the stored procedure. At the stored procedure level, I need to replace the DEF substring with XYZ to get the string "ABC XYZ". How can i do this?

Thank. Nlv

+3
source share
1 answer

Just use the replace function in T-SQL

declare @myOriginalString varchar(50)
set @myOriginalString = 'ABC DEF'
declare @myfindstring varchar(50)
set @myfindstring = 'DEF'
declare @myReplaceString varchar(50)
set @myReplaceString = 'XYZ'

select replace(@myOriginalString,@myFindString, @myReplaceString)
+3
source

Source: https://habr.com/ru/post/1731228/


All Articles