还有请教大侠:有关TOP的应用。急急急请问

Flashsammi 2003-04-01 10:48:04
我在SQL SERVER中写一个存储过程,在存储过程里我declare一个变量@toprecord,@toprecord指定需返回结果集的前若干条记录。
如:select top 5 * from table where ..... 返回前5条记录,现在我想自己确定返回若干条记录,我写了:select top @toprecord * from table where ..... 但是这句非法。
请问这个问题怎么解决?
...全文
49 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-04-01
  • 打赏
  • 举报
回复
exec('select top '+cast(@toprecord as varchar(10))+' from table where.. ')

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧