首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-10 
SQL 存储过程 NOT IN 的问题。SQL codeALTERPROCEDURE sArticle@currentPage int ASdeclare @sql1 varchar(

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,N'@currentPage int',@currentPage 

热点排行