日期:2014-05-18 浏览次数:20495 次
CREATE PROCEDURE Getlist @Classid int, @Total int AS if(@Total>=6) select top 6 * from tb_article where Classid = @Classid else begin select top @Total * from tb_article where Classid = @Classid union all select top (6 - @Total) * from tb_article where Classid = @Classid end
如需要阅读该回复,请登录或注册CSDN!
select top (@Total) * from tb_article where Classid = @Classid
------解决方案--------------------
CREATE PROCEDURE Getlist
@Classid int,
@Total int
AS
if(@Total>=6)
select top 6 * from tb_article where Classid = @Classid
else
begin
declare @sql nvarchar(4000)
set @sql='select top '+ltrim(@Total)+' * from tb_article where Classid = '+ltrim(@Classid)+'
union all
select top '+ltrim(6 - @Total)+' * from tb_article where Classid = '+ltrim(@Classid))
exec(@sql)
end
SQL2K
------解决方案--------------------
top(@Total) 05及以上版本可以。
如果是2000,需要拼接SQL的动态语句去执行。
------解决方案--------------------
select top (@Total) * from tb_article where Classid = @Classid
------解决方案--------------------
如需要阅读该回复,请登录或注册CSDN!