Функция, которую вы можете использовать
create function ThreeUpperInARow(@s varchar(max)) returns bit
begin
declare @Rows int
;with cte as
(
select left(@s, 3) as Part,
stuff(@s, 1, 1, '') as Rest
union all
select left(Rest, 3) as Part,
stuff(Rest, 1, 1, '') as Rest
from cte
where len(Rest) >= 3
)
select @Rows = count(*)
from cte
where upper(Part) = Part COLLATE Latin1_General_CS_AS
return case @Rows when 0
then 0
else 1
end
end
Использование:
declare @T table(ID int identity, Txt varchar(max))
insert into @T
select 'aaaAFAaaaBB' union all
select 'aaaAAaaaBB'
select T.ID,
T.Txt,
dbo.ThreeUpperInARow(T.Txt) as Upp
from @T as T
Результат:
ID Txt Upp
----------- --------------- -----
1 aaaAFAaaaBB 1
2 aaaAAaaaBB 0