表t的字段f类型为char(10),有如下5条记录:0123456789     
210131123 
420    391
3   1    2
910       请问下面集合如何取得:
1.第n位=x的所有记录
  如:n=2, x=1
  则取得第一、第二、第五条记录2.第n位=x、第m位=y的所有记录
  如:n=2, x=1, m=3, y=0
  则取得第二、第五条记录3.扩展到任意几位组合呢?
如果不明白我的意思我再解释。
谢谢!

解决方案 »

  1.   

    如果长度固定可以用abc like '_____x__y_'
      

  2.   

    讨论交流it人的职业生涯,该如何合理的规划,少走一点弯路
    qq群: 12386345
      

  3.   

    create table #t(f char(10))
    insert into #t
    select '0123456789'
    union all select '210131123'
    union all select '420    391'
    union all select '3   1    2'
    union all select '910       'declare @n int,@x char(1)
    select @n=2,@x='1'
    select * from #t where charindex(@x,f)=@n
    /*
    f          
    ---------- 
    0123456789
    210131123 
    910       (所影响的行数为 3 行)
    */
    declare @n int,@x char(1),@m int,@y char(1)
    select @n=2,@x='1',@m=3,@y='0'
    select * from #t where charindex(@x,f)=@n and charindex(@y,f)=@m
    /*
    f          
    ---------- 
    210131123 
    910       (所影响的行数为 2 行)
    */