sql语句中如何将int型转为float型?

解决方案 »

  1.   

    如:
    select a/b from c
    a,b 都是int
    如何将a,b 转为float
    因为a/b的结果是float
      

  2.   

    declare @i int
    declare @j int
    set @j = 2
    set @i = 10
    select @iselect @i *1.0select @i/@jselect @i*1.0/@jselect @i/(@j*1.0)
                
    ----------- 
    10(所影响的行数为 1 行)                
    --------------- 
    10.0(所影响的行数为 1 行)            
    ----------- 
    5(所影响的行数为 1 行)                           
    -------------------------- 
    5.000000000000(所影响的行数为 1 行)                            
    --------------------------- 
    5.00000000000000(所影响的行数为 1 行)
      

  3.   

    int 到float 是隐式转换的,你可用convert进行显式的转换
    试试我上面的写法
      

  4.   

    select cast (列名 as float) as 列名 from 表名