How to update data as upper case first letter with t-sql command?

前端 未结 7 709
别跟我提以往
别跟我提以往 2020-12-28 18:14

I have a table on my database. My table\'s name is \"Company\". I want to change data \"company_name\" as upper case first letter. For example;

\"ABC COMPANY\"

7条回答
  •  悲哀的现实
    2020-12-28 18:23

    A further modification handles possessives ('s) and words starting with Mc

    if ' ' + @OutputString like '% Mc%'
    set @OutputString = ' ' + @OutputString
    set @index = CHARINDEX ( ' Mc', @OutputString)
    while @Index > 0
    begin
        set @OutputString = SUBSTRING(@outputString, 1, @index + 2) + UPPER(SUBSTRING(@outputString, @index + 3, 1)) + SUBSTRING(@outputString, @index + 4, len(@outputString))
        set @index = CHARINDEX ( ' Mc', @OutputString, @Index + 4)
    end
    set @outputstring = ltrim(rtrim(@outputstring))
    
    if @OutputString + ' ' like '%''S %' 
    set @OutputString = ltrim(rtrim(REPLACE(@outputstring + ' ', '''S ', '''s ')))
    

    place right before Return

提交回复
热议问题