开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜