table1的内容
id 
1
12
123
1234
12345
123456
12346
12348
14
128如何能写一个SQL把id在12345内的取出来。
如上表,则选择 1,12,123,1234,12345

解决方案 »

  1.   

    select id from table1 where cast(id as varchar(100))<='12345'
      

  2.   

    select id from table1 where id between 1 and 12345
      

  3.   

    select * from #a where substring('12345',1,len(id))=id
      

  4.   

    LZ应是这个意思吧
    create table #a (id varchar(20))
    insert into #a  values('1')
    insert into #a  values('12')
    insert into #a  values('123') 
    insert into #a  values('1234') 
    insert into #a  values('12345') 
    insert into #a  values('123456') 
    insert into #a  values('12346') 
    insert into #a  values('12348') 
    insert into #a  values('14') 
    insert into #a  values('128')select * from #a where substring('12345',1,len(id))=idid
    --------------------
    1
    12
    123
    1234
    12345(5 行受影响)