1

尝试运行以下代码时出现以下错误:

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
4

2 回答 2

2

尝试转换变量:

select top (cast(@constCnt as int)) *
...
于 2012-07-10T19:40:52.193 回答
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
于 2012-07-10T19:43:40.810 回答