select cast('0054121' as int)
----------------
select cast(fieldname as int)

解决方案 »

  1.   

    --如果表中字段的值全部是数字,那么可以这样
    select convert(int,num) from tab
      

  2.   

    补充一下,num是varchar(7)我用一个办法解决了但是很麻烦啊if left(num,1) ='0' THEN right(num,6)
    else end if
    if left(num,2) ='0' THEN right(num,6)
    else 
    ........
      

  3.   

    select cast(fieldname as int)这样就可以了
      

  4.   

    谢谢楼上的,可是不能直接转INT的,因为有这种数字:0012554.
    最后面多了一个小数点
      

  5.   

    cast 或者convert 都行啊,为什么要这么麻烦?
      

  6.   

    都不可以啊,有的数字最前面或者是最后面多了一个小数点,不能直接转int啊
      

  7.   

    那这样呢???
    select cast(fieldname as float)
      

  8.   

    那这样呢???
    select cast(fieldname as float) 这样不行 因为前面和后面有的有“.”要求把 .0012345 或者 0012345. 或者 0012345 转换成 12345
      

  9.   

    写两条语句
    select convert(int,num) from tab where left(num,1)<>'.' or right(num,1)<>'.'
    select convert(varchar(6),convert(int,left(num,6)))+'.' from tab where right(num,1)='.'
      

  10.   

    select convert(int,num) num from tab where left(num,1)<>'.' or right(num,1)<>'.' 
    union all 
    select convert(varchar(6),convert(int,left(num,6)))+'.' num from tab where right(num,1)='.'
      

  11.   

    自己搞好了
    select cast( n.c as int)  from (select replace(fieldname,'.','') c from tab) n