CREATE PROCEDURE test 
@topnumber int
as
set rowcount @topnumber 
select * from mytable order by date

解决方案 »

  1.   

    也可用exec
    exec('select top '+@topnumber+' * from mytable order by date')
      

  2.   

    exec('select top '+@topnumber+' * from mytable order by date')
    如何返回结果数据?
      

  3.   

    CREATE PROCEDURE browse_house
       @location_sign bit,
       @number intAS 
    set rowcount @number  
    select location,housename,house_id,type,houseprice,housetypes
       from house
       where location_sign=@location_sign
       order by Submission_time desc
    set rowcount 0--最好写上这句话
    GO
      

  4.   

    这是zjcxc(邹建) 大哥帮我解决问题提供另一种方法( ) 
    ....
    AS 
    declare @s Nvarchar(4000)
    set @s='select top '+cast(@number as varchar)+'  location,housename,house_id,type,houseprice,housetypes
       from house
       where location_sign=@location_sign
       order by Submission_time desc'
    exec sp_executesql @s,N'@location_sign bit',@location_sign
    GO