1

我有一个关于如何将字符串中的“/”符号后的第一个下一个字符转换为大写的问题。

举个例子 :

CustomerNameramayanan s/o vicky ratnam

首先我需要它在适当的情况下,所以我使用这个:

Update
dbo.table set CustomerName = dbo.ProperCase(CustomerName)

结果 :Ramayanan S/o Vicky Ratnam

但我需要它是:(应该在Ramayanan S/O Vicky Ratnam之后的第一个字符)/uppercase

4

4 回答 4

1

请检查:

declare @T table(Insurance varchar(max))

insert into @T values ('roeselare')
insert into @T values ('BRUGGE')
insert into @T values ('ramayanan s/o vicky ratnam')

select (
       select upper(T.N.value('.', 'char(1)'))+
                lower(stuff(T.N.value('.', 'varchar(max)'), 1, 1, ''))+(CASE WHEN RIGHT(T.N.value('.', 'varchar(max)'), 1)='/' THEN '' ELSE ' ' END)
       from X.InsXML.nodes('/N') as T(N)
       for xml path(''), type
       ).value('.', 'varchar(max)') as Insurance
from 
  (
  select cast('<N>'+replace(
            replace(
                Insurance, 
                '/', '/</N><N>'),
            ' ', '</N><N>')+'</N>' as xml) as InsXML
  from @T
  ) as X
于 2013-05-13T05:27:35.650 回答
1
UPDATE dbo.[table]
SET CustomerName = REPLACE(ProperCase(CustomerName),
                           SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2),
                           UPPER(SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2)))
WHERE CHARINDEX('/',CustomerName) > 0;

搜索拳头并将其后面的字符/替换为大写的和后面的字符。//

于 2013-05-13T04:59:11.190 回答
0
    Drop Table #Temp
    Create Table #Temp
    (
    CustomerName varchar(100)
    ) 

    Insert into #Temp
    values('Ramayanan S/o vicky ratnam')

    Select * from #temp

    Select  UPPER(SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2)),REPLACE( CustomerName ,
                               SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2),
                               UPPER(SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2))) from #temp


    UPDATE dbo.#Temp
    SET CustomerName = REPLACE( CustomerName ,
                               SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2),
                               UPPER(SUBSTRING(CustomerName, CHARINDEX('/',CustomerName),2))); 

     Select * from #temp                          
于 2013-05-13T05:37:10.513 回答
0
Update dbo.table set CustomerName = REPLACE(CustomerName ,'/o','/O')
于 2013-05-13T04:40:53.213 回答