日期:2014-05-18  浏览次数:20371 次

求个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 int
set @input=1.89
select @temp=(@input-cast(@input as int)),@temp1=cast(@input as int)
if @temp>0.60
    begin
        set @temp=@temp-0.60
        set @temp1=@temp1+1
    end
else
    begin
        set @temp=0
        set @temp1=@temp1+1
    end

select @temp1+@temp

------解决方案--------------------
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.89
select case when @d*100%100>=60 then @d+0.4 else @d end