亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SQL Server:使所有大寫字母變為正確的字母/標題字母

SQL Server:使所有大寫字母變為正確的字母/標題字母

慕少森 2019-11-11 15:59:41
我有一個作為所有大寫字母導入的表,我想將其轉換為大寫字母。你們使用什么腳本來完成此任務?
查看完整描述

3 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

這是可以解決問題的UDF ...


create function ProperCase(@Text as varchar(8000))

returns varchar(8000)

as

begin

  declare @Reset bit;

  declare @Ret varchar(8000);

  declare @i int;

  declare @c char(1);


  if @Text is null

    return null;


  select @Reset = 1, @i = 1, @Ret = '';


  while (@i <= len(@Text))

    select @c = substring(@Text, @i, 1),

      @Ret = @Ret + case when @Reset = 1 then UPPER(@c) else LOWER(@c) end,

      @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,

      @i = @i + 1

  return @Ret

end

但是,您仍然必須使用它來更新數據。


查看完整回答
反對 回復 2019-11-11
?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

我玩游戲有點晚了,但是我相信這是更實用的功能,并且可以與任何語言一起使用,包括俄語,德語,泰語,越南語等。它將在'或-或之后加上大寫字母。或(或)或空格(顯然是:)。


CREATE FUNCTION [dbo].[fnToProperCase]( @name nvarchar(500) )

RETURNS nvarchar(500)

AS

BEGIN

declare @pos    int = 1

      , @pos2   int


if (@name <> '')--or @name = lower(@name) collate SQL_Latin1_General_CP1_CS_AS or @name = upper(@name) collate SQL_Latin1_General_CP1_CS_AS)

begin

    set @name = lower(rtrim(@name))

    while (1 = 1)

    begin

        set @name = stuff(@name, @pos, 1, upper(substring(@name, @pos, 1)))

        set @pos2 = patindex('%[- ''.)(]%', substring(@name, @pos, 500))

        set @pos += @pos2

        if (isnull(@pos2, 0) = 0 or @pos > len(@name))

            break

    end

end


return @name

END

GO


查看完整回答
反對 回復 2019-11-11
  • 3 回答
  • 0 關注
  • 572 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號