CREATE FUNCTION F_Covert(
@str nvarchar(4000)
) returns nvarchar(4000)
as
begin
declare @endp int,@endflag int,@length int,@i int
,@reversestr nvarchar(4000),@return_str nvarchar(4000)
select @endflag = 0,@length=len(@str),@i=1,@reversestr = reverse(@str),@endp = 0
while (@endflag = 0 and @i<=@length)
begin
if(SUBSTRING(@reversestr,@i,1) != ‘? ‘)
begin
set @endflag = 1
set @endp = @length - @i + 1
end
set @i = @i + 1
end
set @return_str = substring(@str,1,@endp)
return @return_str
end
原文:http://www.cnblogs.com/JoePotter/p/4992188.html