select * from temp2
结果是 读数这列是 114.57000000000001
我想把这列变成  114
怎么写

解决方案 »

  1.   

    select cast(列 as int) as '列名' from temp2
      

  2.   

    服务器: 消息 245,级别 16,状态 1,行 1
    将 nvarchar 值 '114.57000000000001' 转换为数据类型为 int 的列时发生语法错误。
      

  3.   

    declare @tb table (num nvarchar(500))
    insert into @tb select '114.57000000000001'select left(num,charindex('.',num)-1) from @tb114
      

  4.   


    select convert(int,114.57000000000001)
      

  5.   


    declare @tb table (num nvarchar(500))
    insert into @tb select '114.57000000000001'select 
    case when ceiling(num)>num then ceiling(num)-1 else num end as num 
    from @tb114
      

  6.   

    要使用round,如果用cast或convert得到的结果是115
    试一下SELECT ROUND(150.75, 0, 1)就知道了
      

  7.   

    SELECT CAST(CAST(列名 AS decimal(10,1)) as int) as '列名' from temp2
      

  8.   

    DECLARE @myval nvarchar  (50)
    SET @myval = 114.57000000000001
    SELECT CAST(CAST(@myval AS decimal(10,1)) as int)
      

  9.   

    谢谢 一样的出错服务器: 消息 8114,级别 16,状态 5,行 1
    将数据类型 nvarchar 转换为 numeric 时出错。我的数据在表格里面是整数导入里面就变成带小数的  
      

  10.   


    select cast(floor('114.57000000000001') as int)
      

  11.   

    select left(列名,3)from temp2
      

  12.   

    declare @tb table (num nvarchar(500))
    insert into @tb select '114.57000000000001'
    insert into @tb select 'a'
    --查询
    select 
    case when ceiling(num)>num then ceiling(num)-1 else num end as num 
    from @tb
    where isnumeric(num)=1
    --看看有什么数据不是数字类型的
    select * from @tb
    where isnumeric(num)=0
      

  13.   

    谢谢拉  我是这样做的  我一开始把他转换成FLOAT  然后转换成NUMERIC  就可以了
      

  14.   

    select cast(列 as int) as '列名' from temp2