一个选择是使用一个组合 Charindex
和 Substring
. 注意到在以下 100
应该只是声明的长度列charindex将永远停留在底string.
这不需要的结尾的括号,它看起来对最后一位数字。
with t as (
select * from (values
('ProALPHA - S - HTML Custom Table implementation (E001445)' ),
('IKA CP Implementation (Aus) (E001534-0001)' ),
('Test Engagment Integration: (E001637-0003) Non-billable' ),
('Customer requests customization for Analytics and Java Migration - E000797' ),
('Create list with customers renewing in H2 2020' )
)t(title)
)
select title,
Iif(title like '%E00%',Reverse(Substring(part,patindex('%[0-9]%',part),100)),null)
from t
cross apply (values( Reverse(Substring(t.title, CharIndex('E00',t.title), 100 )) ))x(part)
例如小提琴
更新
你 可以 实现上述作为 计算列 的帮助的一个 功能 来代替使用中的 应用.
这可能是罚款使用情况,虽然我建议使用一个 图 ,如果在所有可能的。
create function dbo.E00_Part(@title varchar(100))
returns varchar(100)
as
begin
return (select Reverse(Substring(@title, CharIndex('E00',@title), 100 )))
end
create table T (title varchar(100),
Computed as Iif(title like '%E00%',
Reverse(Substring(dbo.E00_Part(title),patindex('%[0-9]%',dbo.E00_Part(title)),100)),null))
看到演示的小提琴2