Technical Article

Recursive Replace Function

,

User Defined Function that recursively replaces string1 from string2

Create Function ReplaceRecursive
(@Input varchar(8000), @Find varchar(100), @Replace varchar(100))
RETURNS varchar(8000)
BEGIN	
	Declare @Output 	varchar(8000)
	Declare @Counter 	int
	
	Set	@Output = @Input
	Set	@Counter = 1

	While 	@Counter <= Len(@Output)
	Begin
		Set @Output  = Replace(@Output, @Find, @Replace)
	        Set @Counter = @Counter + 1
	End
	
	
	Return	@Output
END

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating