你的意思是用这个:AND  ((cast(substring(料号,3,2) as int)>=12) and (cast(substring(料号,3,2) as int)<=20))替换   AND  (substring(料号,3,2) in ('12','13','14','15','16','17','18','19','20'))之后,没有起作用吗?

解决方案 »

  1.   

    你看看这个两个语句返回的结果一样吗:select* 
    from ListDetail
    WHERE CJRWH=@CJRWH
    AND  charindex('*',料号)>0 
            AND  (substring(料号,1,2)='3Y' and  (substring(料号,1,3) not in('3YA''3YB','3YC')))
            AND  ((cast(substring(料号,3,2) as int)>=12) and (cast(substring(料号,3,2) as int)<=20))
            
    select* 
    from ListDetail
    WHERE CJRWH=@CJRWH
    AND  charindex('*',料号)>0 
            AND  (substring(料号,1,2)='3Y' and  (substring(料号,1,3) not in('3YA''3YB','3YC')))  
            AND  (substring(料号,3,2) in ('12','13','14','15','16','17','18','19','20'))
            
      

  2.   

    2000有没有isnumeric函数?有的话测试一下cast(substring(料号,3,2) as int)是否为数值型
      

  3.   

    @阳泉酒家小当家
    是的。
       AND  ((cast(substring(料号,3,2) as int)>=12) and (cast(substring(料号,3,2) as int)<=20))  --不起作用
     
       AND  (substring(料号,3,2) in ('12','13','14','15','16','17','18','19','20'))--起作用
    cast(substring(料号,3,2) as int)  应该是整数,因为再除个整数能获取到结果
      

  4.   


    把这个:AND  ((cast(substring(料号,3,2) as int)>=12) and (cast(substring(料号,3,2) as int)<=20))  --不起作用改成这样呢:AND  substring(料号,3,2)>='12' and substring(料号,3,2)<='20'看看能起作用吗