帮我优化一下这个存储过程

goodflash 2003-07-18 05:33:34
declare @tempsql varchar(8000)

begin
set @tempsql='select top' +str(@temp_ipage)+ ' * from table1 where id=1 and id not in (select top '+str(@temp_spage)+' id from table1 where id=1) order by id desc'
execute(@tempsql)
end

如果@temp_spage的数量特别多,效率就会低,而且@tempsql的长度8000也不够用。。。有什么办法实现类似功能???
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangvxin1 2003-07-20
  • 打赏
  • 举报
回复
占座学习,哈哈
yangvxin1 2003-07-20
  • 打赏
  • 举报
回复
占座看看
goodflash 2003-07-20
  • 打赏
  • 举报
回复
up...

怎么样用其他语句实现类似功能?

比如 ... and id>...
不用not in
erigido 2003-07-18
  • 打赏
  • 举报
回复
占座学习。
pengdali 2003-07-18
  • 打赏
  • 举报
回复
declare @tempsql1 varchar(8000)
declare @tempsql2 varchar(8000)

begin
set @tempsql1='select top' +str(@temp_ipage)+ ' * from table1 where id=1 and id '
set @tempsql2='not in (select top '+str(@temp_spage)+' id from table1 where id=1) order by id desc'
execute(@tempsql1+@tempsql2)
end
yehuazi 2003-07-18
  • 打赏
  • 举报
回复
exec('select top' +str(@temp_ipage)+ ' * from table1 where id=1 and id not in (select top '+str(@temp_spage)+' id from table1 where id=1) order by id desc')

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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