当前位置: 代码迷 >> Sql Server >> SQL 存储过程 NOT IN 的有关问题
  详细解决方案

SQL 存储过程 NOT IN 的有关问题

热度:59   发布时间:2016-04-27 18:42:38.0
SQL 存储过程 NOT IN 的问题。
SQL code
ALTER     PROCEDURE sArticle  @currentPage int ASdeclare @sql1 varchar(250)declare @sql2 varchar(250) set @sql1 ='select top 20 ID,Topic,Author,AddTime,ViewNum from Article order by ID desc'set @sql2 ='select top 20 ID,Topic,Author,AddTime,ViewNum from Article where ID not in ([color=#FF0000]select top (@currentPage-1)*20 ID from Article order by ID desc[/color]) order by ID desc'if (@currentPage=1)   execute (@sql1)else  execute (@sql2)


Not IN (1,2,3,4 ...) 上面红色的语句,怎样写才是正确的?

------解决方案--------------------
TOP 后不能跟一个变量。
------解决方案--------------------
你是2000还是05?加()就行了吧

SQL code
ALTER     PROCEDURE sArticle  @currentPage int ASdeclare @sql1 nvarchar(250)declare @sql2 nvarchar(250) set @sql1 ='select top 20 ID,Topic,Author,AddTime,ViewNum from Article order by ID desc'set @sql2 ='select top 20 ID,Topic,Author,AddTime,ViewNum from Article where ID not in (select top ((@currentPage-1)*20) ID from Article order by ID desc) order by ID desc'if (@currentPage=1)   execute (@sql1)else exec sp_executesql @sql2,[email protected] int',@currentPage
  相关解决方案