如果字段在单元格中具有重复值,是否有一种评估字段的方法。例如,如果某人按住数字键并返回“ 00000”或“ 222222222”或“ 333”的某种变化形式,则该值只能在此字段中为数字。我正在寻找一种查询可能会出现这种模式的字段的方法。
以下查找模式,即333 …或123 …或987 …
可以将其想象为Rummy 500 …运行和3或更多的组。
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
退货
col 5555 6789 22222 45678 55555 77777 55555555 98765432
现在,如果您不想识别“运行”(123 …)”,只需删除以下内容:
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