A表有一int型字段ID
我现在传进来一个条件,要跟ID的前5位进行比较select * from A where (ID)前5位 = 条件这个怎么写?

解决方案 »

  1.   

    select * from A where substring(cast(id as char(20)),1,5) = 条件
      

  2.   

    select * from A where left(ltrim(ID),5)=条件
      

  3.   

    select top 5 * from A WHERE in(。)
      

  4.   


    select * from A where left(ltrim(ID),5) = 条件
      

  5.   

    截取字段  substring
    select * from A where substring(ID,0,5) =12345
    select * from A where left(ID,5) = 12345 
      

  6.   

    select * from A where left(ltrim(ID),5)=条件
      

  7.   

    int 不用强制转换的,系统会默认变为字符
      

  8.   

    [Quote=引用 2 楼 qianjin036a 的回复:]select * from A where left(ltrim(ID),5)=条件