floor相关

declare @f int =5
select floor(@f*0.22)
-- 直接可显示结果

create table demo(
id int identity(1,1),
id1 int
)

select * from demo
insert into demo(id1)
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6

--select top (FLOOR(@f*0.23)) * from dbo.demo
/* 消息 1060,级别 15,状态 1,第 17 行
TOP 子句中的行数必须是整数。 */ 

select top (CAST(FLOOR(@f*0.5) AS int)) * from dbo.demo
-- 这样就可以得到我们所想要的结果

貌似是floor后面的整数在top之中不能够被识别出来。

posted @ 2014-06-15 22:07  _cc  阅读(370)  评论(0编辑  收藏  举报