select 
(case  ltrim(rtrim(boot_time)) 
when boot_time = NULL then boot_time = 0
else cast(boot_time as float) end) as boot_time 
from plandetails
麻煩看下哪里問題因為boot_time在表里是char類型
我在to excel的時候要把它轉換為float類型
但是其中也有Null值

解决方案 »

  1.   

    select cast(boot_time as decimal(18,2))
      

  2.   

    select cast(isnull(boot_time,0) as decimal(18,2)) from plandetails
      

  3.   


    Server: Msg 8114, Level 16, State 5, Line 1
    将数据类型 varchar 转换为 numeric 时出错。
      

  4.   


    select case when  boot_time is not null then cast(boot_time as float) else 0 end   from plandetails 
      

  5.   

     cast(boot_time as float)有问题
    当boot_time含有: -  /就不能转成float
    select cast(boot_time as decimal(18,2))
    或者把: -  /去掉再转为float
     cast(replace(boot_time,"-","") as float
      

  6.   

    boot_time as float
    boot_time 含有-/等符号,你怎么把它转成为float啊
      

  7.   

    select cast(isnull(boot_time,0) as decimal(18,2)) from plandetails where isnumeric(boot_time)=1 or boot_time is null
      

  8.   


    我如果不想加where該怎么解決?
      

  9.   

    Server: Msg 8114, Level 16, State 5, Line 1
    将数据类型 varchar 转换为 float 时出错。