SQL Server 得到行号的SQL
SQL Server 得到行号的SQL
使用临时表:
select id=identity(int,1,1),value into #temp from YourTable
select * from #temp
drop table #temp
取得第11到20行记录:
select IDENTITY(int, 1,1) AS ID_Num,* into #temp from 表
select * from #temp where ID_Num>10 and ID_Num<=20
或
SELECT Top @PageSize *
from T
WHERE SortField NOT IN (SELECT TOP @PageSize * @Pagei SortField
from T
ORDER BY SortField
)
ORDER BY SortField
REF:http://topic.csdn.net/t/20021022/21/1116380.html
相关文档:
原网站无法访问,故保留google快照
How things work :
SQL
Select
Statement
Introduction
:
Ever asked your self how things work inside the
SQL
Select
statement? In this article we won’t be talking about how to writeSQL
Select
statem ......
Cross Apply使表可以和表值函数结果进行join, 这样表值函数的参数就可以使用一个结果集,而不是一个标量值,下面是book online的原文,有例子,有解释。
The APPLY operator allows you to invoke a table-valued function for each row returned by an outer table expression of a query. The table-valued function act ......
#Region " 命名空间 "
Imports System.Data
Imports System.Data.SqlClient
#End Region
Public Class DBCommon
Implements IDisposable
#Region " 成员变量 "
Private conn As SqlConnection
Private cmd As SqlCommand
Private trans As SqlTransaction
#End Region
#Region " 构造函数 "
......
应一个朋友的要求,贴上收藏的SQL常用分页的办法~~
表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
语句形式:
SELECT TOP 页记录数量 *
from 表名
WHERE (ID NOT IN
(SELECT TOP (每页行数*(页数-1)) ID
from 表名
ORDER BY ......