当前位置: 代码迷 >> Sql Server >> 求个Sql 函数,该怎么解决
  详细解决方案

求个Sql 函数,该怎么解决

热度:27   发布时间:2016-04-27 12:22:29.0
求个Sql 函数
将字段的值进行一些处理, 字段是decimal类型, 后面有2位小数。 如果后2位小数大于60 ,则减去60,小数前的数字加1
否则不变。
如10.60 ,返回11.0 , 1.89 返回2.29, 3.30 返回还是 3.30

谢谢指教

------解决方案--------------------
SQL code
declare @input as decimal(10,2)declare @temp as decimal(10,2)declare @temp1 as intset @input=1.89select @temp=(@input-cast(@input as int)),@temp1=cast(@input as int)if @temp>0.60    begin        set @[email protected]        set @[email protected]+1    endelse    begin        set @temp=0        set @[email protected]+1    endselect @[email protected]
------解决方案--------------------
declare @n decimal(5,2)

set @n=12.61

select case when right(CONVERT(varchar(8), @n),2)>='6' then @n+0.4 else @n end


---------------------------------------
13.01

(1 行受影响)
------解决方案--------------------
SQL code
declare @d dec(18,2)set @d=1.89select case when @d*100%100>=60 then @d+0.4 else @d end
  相关解决方案