--select Right (@strReplace,-2)
/*
Loop replaces a string
Set @strReplace = ' City; district; company ' characters to be replaced, separated by semicolons
Set @strTest = ' xiamen Simin District XXX Information Technology Co., Ltd ' the original string to be replaced
*/
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].getarraryreplacestr ') and xtype= ' FN ')
Drop function Getarraryreplacestr
Go
Create function Getarraryreplacestr (@strReplace varchar (1000), @strTest varchar (1000))
Returns varchar (100)
As
Begin
declare @start int, @end int, @len int, @strTmp varchar (1000)
Set @start =0
Set @len =len (@strReplace)
while (@len >0)
Begin
--select @start
Select @end =charindex ('; ', @strReplace)
--select @end
If @start = @end
Begin
Set @len =0
Select @strTest =replace (@strTest, @strReplace, ")
End
Else
Begin
Set @len = @end-@start
--select @len
Select @strTmp =substring (@strReplace, @start, @len)
Select @strReplace =replace (@strReplace, @strTmp + '; ', ')
--select @strReplace
Select @strTest =replace (@strTest, @strTmp, ")
--set @start = @end
End
End
Return @strTest
End
Go
DECLARE @strReplace varchar (1000), @strTest varchar (1000), @strTmp varchar (1000)
Set @strReplace = ' City; district; company '
Set @strTest = ' xiamen Simin District XXX Information Technology Co., Ltd. '
Select Dbo.getarraryreplacestr (@strReplace, @strTest)