Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/2/1 0:14:58 sqlserver过滤字符串中的空格的自定义函数_[SQL,Server教程]
去掉字符串中的所有空格
CREATE Function f_trimstr(@str varchar(100))
returns varchar(100)
AS
begin
declare @i intdeclare @s1 varchar(50)declare @result varchar(100)declare @len int
select @result = ''select @str = ltrim(rtrim(@str))select @len = len(@str)select @i = 1
while @i<=@lenbegin select @s1 = substring(@str,@i,1) if(@s1<>'') begin select @result = @result + @s1 end select @i = @i + 1end
return @result
end
赞