尝试运行以下代码时出现以下错误:
TOP子句中的行数必须是整数。
@constCnt变量声明为SMALLINT,而@thresh声明为DECIMAL(6,4)。当我执行select (floor((@constCnt*(1+@thresh))))
时,我得到一个没有小数的返回的整数值。
任何想法如何解决这个问题?
select top (@constCnt) *
into #temp
from (
select top (floor((@constCnt*(1+@thresh)))) pt.*,
inLast = CASE WHEN lh.code IS NULL THEN 0 ELSE 1 END
from #pretemp pt
left join #last lh
on lh.code = pt.code
order by em desc ) a
order by inlast desc, emr desc, code
答案 0 :(得分:2)
尝试转换变量:
select top (cast(@constCnt as int)) *
...
答案 1 :(得分:0)
您可以通过定义另一个变量来完成此操作:
declare @constCnt2 int = floor((@constCnt*(1+@thresh)))
然后在子查询中使用它。
select top (@constCnt) *
into #temp
from (select top (@constCnt2) pt.*,
inLast = CASE WHEN lh.code IS NULL THEN 0 ELSE 1 END
from #pretemp pt left join
#last lh
on lh.code = pt.code
order by em desc
) a
order by inlast desc, emr desc, code