Berikut ini menemukan pola yaitu 333... atau 123... atau 987...
Anggap saja seperti Rummy 500... Lari dan grup beranggotakan 3 orang atau lebih.
Declare @Table table (col int)
Insert into @Table values
(4141243),(4290577),(98765432),(78635389),(4141243),(22222),(4290046),(55555555),(4141243),(6789),(77777),(45678),(4294461),(55555),(4141243),(5555)
Declare @Num table (Num int);Insert Into @Num values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)
Select Distinct A.*
From @Table A
Join (
Select Patt=replicate(Num,3) from @Num
Union All
Select Patt=right('000'+cast((Num*100+Num*10+Num)+12 as varchar(5)),3) from @Num where Num<8
Union All
Select Patt=reverse(right('000'+cast((Num*100+Num*10+Num)+12 as varchar(5)),3)) from @Num where Num<8
) B on CharIndex(Patt,cast(col as varchar(25)))>0
Kembali
col
5555
6789
22222
45678
55555
77777
55555555
98765432
Sekarang, Jika Anda tidak ingin mengidentifikasi "berjalan" (123...)", hapus saja yang berikut ini:
Union All
Select Patt=right('000'+cast((Num*100+Num*10+Num)+12 as varchar(5)),3) from @Num where Num<8
Union All
Select Patt=reverse(right('000'+cast((Num*100+Num*10+Num)+12 as varchar(5)),3)) from @Num where Num<8