select * from mytable where myname like 'abcd%' and len(myname) <= 8

解决方案 »

  1.   

    create table tb(MyId int, MyName varchar(10))
    Insert into tb 
    select '1','ABCD123456'
    union all select '2','ABCD12345'
    union all select '3','ABCD1234'
    union all select '4','ABCD123'
    union all select '5','ABCD12'
    union all select '6','ABCD1'
    union all select '7','ZZZZ123456'
    union all select '8','ZZZZ12345'
    union all select '9','ZZZZ1234'
    union all select '10','ZZZZ123'
    select MyName from tb where MyName like 'ABCD%' and len(MyName)<=8--结果MyName
    ABCD1234
    ABCD123
    ABCD12
    ABCD1