首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求个Sql 函数,该怎么解决

2012-06-15 
求个Sql 函数将字段的值进行一些处理, 字段是decimal类型, 后面有2位小数。 如果后2位小数大于60 ,则减去60

求个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 @temp=@temp-0.60        set @temp1=@temp1+1    endelse    begin        set @temp=0        set @temp1=@temp1+1    endselect @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.89select case when @d*100%100>=60 then @d+0.4 else @d end 

热点排行