日期:2014-05-18  浏览次数:20501 次

sql server 2000 分页问题
SQL code
CREATE PROCEDURE [DBO].[Job_SearchPerson] 
    @PIndex    int,
    @PSize        int,
    @ZWP        int,
    @area        int
    AS
        SELECT TOP (@PSize) [姓名]
        FROM [TAB1]
        WHERE  ID NOT IN (SELECT TOP (@PSize*(@PIndex-1))  ID  FROM [TAB1] ORDER BY [姓名]) 
        ORDER BY [姓名]
    GO
 


上边的存储过程在 sql server 2008 中正确,但是在 sql server 2000 中却提示错误

错误170:第一行:'('附近有语法错误。

------解决方案--------------------
SQL code
EXEC(
'ELECT TOP '+@PSize'+ [姓名]
        FROM [TAB1]
        WHERE  ID NOT IN (SELECT TOP '+@PSize*(@PIndex-1)'+  ID  FROM [TAB1] ORDER BY [姓名]) 
        ORDER BY [姓名]'
)