UFN_STRING_CAPITALIZE
Return
Return Type |
---|
nvarchar(150) |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@INPUTSTRING | nvarchar(150) | IN |
Definition
Copy
create function dbo.UFN_STRING_CAPITALIZE(
@INPUTSTRING nvarchar(150)
)
returns nvarchar(150)
as
begin
declare @INDEX int
declare @CHAR char(1)
declare @PREVCHAR char(1)
declare @OUTPUTSTRING nvarchar(150)
set @OUTPUTSTRING = lower(@INPUTSTRING)
set @INDEX = 1
while @INDEX <= len(@INPUTSTRING)
begin
set @CHAR = substring(@INPUTSTRING, @INDEX, 1)
set @PREVCHAR = case when @INDEX = 1 then '' else substring(@INPUTSTRING, @INDEX - 1, 1) end
if @PREVCHAR in (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(')
begin
if @PREVCHAR != '''' or upper(@CHAR) != 'S'
set @OUTPUTSTRING = stuff(@OUTPUTSTRING, @INDEX, 1, upper(@CHAR))
end
set @INDEX = @INDEX + 1
end
return @OUTPUTSTRING
end