如下的存储过程 现在只能固定的取前4条记录,怎么改 能传入一个参数 动态的来决定取记录的条数? 
CREATE PROCEDURE getHotTourList
(@tType int,@tTop int)
AS
SELECT  top 4 * FROM cityTour
where
tType = @tType
and
tTop=@tTop
GO

解决方案 »

  1.   

    CREATE PROCEDURE getHotTourList (@tType int,@tTop int, @topV int)
    ASexec 'SELECT  top ' + @topV + ' * FROM cityTour where tType = ' + @tType + ' and tTop=' + @tTop
    GO
      

  2.   

    CREATE PROCEDURE getHotTourList
    (@tType int,@tTop int,@lineCount int)
    ASdeclare @sql varchar(1024)set @sql = 'SELECT  top ' + cast(@lineCount  as varchar(128)) + ' * FROM cityTour
    where
     tType = ' + cast( @tType as varchar(128)) + 
    ' and
     tTop= ' + cast(@tTop as varchar(128)) exec @sql
      

  3.   

    CREATE PROCEDURE getHotTourList(@nums=5)
    (@tType int,@tTop int)
    AS
    SELECT  top @nums * FROM cityTour
    where
    tType = @tType
    and
    tTop=@tTop
    GO
      

  4.   

    我的也少了个类型号说明了.
    CREATE PROCEDURE getHotTourList(@nums int=5)
    (@tType int,@tTop int)
    AS
    SELECT  top @nums * FROM cityTour
    where
    tType = @tType
    and
    tTop=@tTop
    GO
      

  5.   

    brightheroes(闭关|那一剑的风情) 大哥你的方法可以的,到时一定给分了 谢谢了
      

  6.   

    luluso(相约中国大陆最南端-湛江是我家、爱护靠大家)大哥你的还是出错啊
      

  7.   

    这个要用exec来动态执行sql