开发者

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

开发者 https://www.devze.com 2022-12-18 19:34 出处:网络
I\'ve the following requirement. I\'m passing \'ABC DEF\' as a command parame开发者_JS百科ter @MyString to a stored procedure. In the stored procedure level i need to replace the substring DEF with XY

I've the following requirement. I'm passing 'ABC DEF' as a command parame开发者_JS百科ter @MyString to a stored procedure. In the stored procedure level i need to replace the substring DEF with XYZ to get the string 'ABC XYZ'. How can i do that?

Thank you. NLV


Just use the replace function within 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消