views:

27

answers:

1

Hello all,

I've the following requirement. I'm passing 'ABC DEF' as a command parameter @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

+1  A: 

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)
Andrew
Very quick. Great! Thank you Andrew.
NLV