select no=Identity(int,1,1), * into #temptable from whs_department;
Select * From #temptable;
Drop Table #temptable;
分号很重要,不要忘了,我用的是sql server 2005 management studio, 执行前其语法分析器会提示identity不合法,理由是2005的数据库语法已经不支持identity了,取ROW_NUMBER函数代之,无视之,即可正确执行
也可以用top分页
通用语法:
select * from ( select top @pageSize * from ( select top (@pageSize*@currentPage) * from table order by _id asc )t1
order by _id desc )t2 order by _id asc
以上语句含义是在母集中按倒序方法取得的top n,即正序中的bottom n,中间项可先取大母集中的小母集再倒序
某一实例:
SELECT DEPT_NO, DEPT_NAME, DEPT_TYPE
FROM (SELECT TOP 5 DEPT_NO, DEPT_NAME, DEPT_TYPE
FROM (SELECT TOP 15 DEPT_NO, DEPT_NAME, DEPT_TYPE
FROM WHS_DEPARTMENT
WHERE (DEPT_TYPE = 1)
ORDER BY DEPT_NO) AS t1
ORDER BY DEPT_NO DESC) AS t2
ORDER BY DEPT_NO