这个问题是不言自明的.你能指出一种在字符串的每个大写字母之间放置空格的方法.
SELECT dbo.SpaceBeforeCap('ThisIsATestString')
会导致
This Is A Test String.
解决方法
假设sql Server 2005或更高版本,从这里修改的代码修改为:
http://www.kodyaz.com/articles/case-sensitive-sql-split-function.aspx
CREATE FUNCTION SpaceBeforeCap ( @str nvarchar(max) ) returns nvarchar(max) as begin declare @i int,@j int declare @returnval nvarchar(max) set @returnval = '' select @i = 1,@j = len(@str) declare @w nvarchar(max) while @i <= @j begin if substring(@str,@i,1) = UPPER(substring(@str,1)) collate Latin1_General_CS_AS begin if @w is not null set @returnval = @returnval + ' ' + @w set @w = substring(@str,1) end else set @w = @w + substring(@str,1) set @i = @i + 1 end if @w is not null set @returnval = @returnval + ' ' + @w return ltrim(@returnval) end
这可以像上面的建议一样被调用.