declare @t int=20 --这个@T的值是动态的
select top (@t*0.2) * from test

解决方案 »

  1.   

    如果是2005+
    直接
    select top (@t*0.2) * from test如果是2000
    exec('select top ' +@t*0.2+ ' from test')
      

  2.   


    sql 2008 r2 报错
    Msg 1060, Level 15, State 1, Line 3
    The number of rows in the TOP clause must be an integer.
      

  3.   

    --try
    select top cast((@t*0.2) as int) * from test
      

  4.   


    Msg 102, Level 15, State 1, Line 4
    Incorrect syntax near 'cast'.
      

  5.   

    declare @i int
    set @i=20set @i=@i*0.2
    select top (@i)* from sysobjects
      

  6.   

    top (@i*n)--n不能用小数,必髯用整数