Create function pTitleCase(@StrIn nvarchar(1024))
returns nvarchar(1024)
as
  begin
       declare
            @StrOut nvarchar(1024),
            @CurrentPosition int,
            @NextSpace int,
            @CurrentWord nvarchar(1024),
            @StrLen int,
            @LastWord bit

        set  @NextSpace =1
        set  @CurrentPosition =1
        set  @StrOut=''
        set  @StrLen=len(@StrIn)
        set  @LastWord=0
        while  @LastWord=0
                begin
                      set  @NextSpace = charindex(' ',@StrIn , @CurrentPosition+1)
                      if @NextSpace = 0   --no more spaces found
                                 begin
                                       set @NextSpace=@StrLen
                                       set @LastWord=1
                                  end
                          set @CurrentWord= upper(substring(@StrIn,@CurrentPosition , 1))
                          set @CurrentWord=@CurrentWord +lower(Substring(@StrIn,@CurrentPosition+1,@NextSpace -@CurrentPosition))
                          set @StrOut=@StrOut+@CurrentWord
                          set @CurrentPosition =@NextSpace +1
                    end
              return @StrOut
end

posted on 2006-01-16 14:42  戒持飛鳥  阅读(125)  评论(0)    收藏  举报