我在下面有一些示例数据,并希望删除至少2个字符或可以说双头大写字母的所有大写字母。
HON MANI no St.Chom Chao Trapeang Thloeng Chaom Chau Dangkao
LAY NA 35 st 70 Phum10 Boeng Salang Tuol Kouk Phnom Penh
OK KEMEUN Ek Phnom , Battam Bang
CY VANN Rukkhak Kiri ,Battam Bang
LENG EUN , Korng Pisei , Kampong Speu
SEK HONG , Phnom Sruoch , Kampong Speu
我想在没有姓名
的情况下获得如下结果no St.Chom Chao Trapeang Thloeng Chaom Chau Dangkao
35 st 70 Phum10 Boeng Salang Tuol Kouk Phnom Penh
Ek Phnom , Battam Bang
Rukkhak Kiri ,Battam Bang
,Korng Pisei , Kampong Speu
, Phnom Sruoch , Kampong Speu
请知道。
答案 0 :(得分:1)
类似这样的事情
; with data as
(
select line = 'HON MANI no St.Chom Chao Trapeang Thloeng Chaom Chau Dangkao' union all
select line = 'LAY NA 35 st 70 Phum10 Boeng Salang Tuol Kouk Phnom Penh ' union all
select line = 'OK KEMEUN Ek Phnom , Battam Bang' union all
select line = 'CY VANN Rukkhak Kiri ,Battam Bang' union all
select line = 'LENG EUN , Korng Pisei , Kampong Speu' union all
select line = 'SEK HONG , Phnom Sruoch , Kampong Speu'
)
select *,
result = case when first_two_word = upper(first_two_word)
then replace(line, first_two_word, '')
else line
end
from data
cross apply
(
select first_two_word = left(line, charindex(' ', line, charindex(' ', line) + 1))
) w
答案 1 :(得分:1)
您可以通过创建标量值函数
来获得结果CREATE FUNCTION dbo.getLowerCaseString(@String VARCHAR(300))
RETURNS VARCHAR(300)
AS
BEGIN
WHILE(PATINDEX('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZ]%',LTRIM(@String) COLLATE Latin1_General_CS_AS )>0)
BEGIN
SET @String = STUFF(@String,PATINDEX('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZ]%',LTRIM(@String) COLLATE Latin1_General_CS_AS ) ,CHARINDEX(' ',LTRIM(@String)),'')
END
RETURN @String
END
GO
调用函数
SELECT
dbo.getLowerCaseString(StringColumn)
FROM
YourTable