您可以使用select頂部
SELECT TOP 50%* FROM人(http://www.w3schools.com/sql/sql_top.asp)
或
不要這樣分頁會幫你
CREATE PROCEDURE [dbo].[GetRequestedRecordByPage]
@FromList nvarchar(200) -- Table Name
,@SortingCol nvarchar(200) -- Sorting column Name
,@SelectList nvarchar(200) = '*' -- Select columns list
,@WhereClause nvarchar(200) = '' -- Where clause i.e condition
,@PageNum int = 1 -- Requested page number
,@PageSize int = 5 -- No of record in page
,@TotalNoOfRecord int output -- Total no of selected records
AS
Begin
SET NOCOUNT ON
DECLARE @Query nvarchar(max) -- query going to be execute
IF rtrim(ltrim(@WhereClause)) <> ''
BEGIN
SET @Query ='SELECT @TotalNoOfRecord = COUNT(*)
FROM ' + @FromList + '
WHERE ' + @WhereClause
END
ELSE
BEGIN
SET @Query ='SELECT @TotalNoOfRecord = COUNT(*)
FROM ' + @FromList
END
/* Count no. of record */
EXEC sp_executeSQL
@Query,
@params = N'@TotalNoOfRecord INT OUTPUT',
= @TotalNoOfRecord OUTPUT
DECLARE @lbound int, @ubound int
/* Calculating upper and lower bound */
SET @lbound = ((@PageNum - 1) * @PageSize)
SET @ubound = @lbound + @PageSize + 1
/* Get list of record(s) */
SELECT @Query = ''
SELECT @Query = 'SELECT *
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ' + @SortingCol + ') AS rownumber,' [email protected] +
' FROM ' + @FromList
IF rtrim(ltrim(@WhereClause)) <> ''
BEGIN
SELECT @Query = @Query + ' WHERE ' + @WhereClause
END
SELECT @Query = @Query + ' ) AS tbl
WHERE rownumber > ' + CONVERT(varchar(9), @lbound) +
' AND rownumber < ' + CONVERT(varchar(9), @ubound)
EXEC (@Query)
End
將是臨時的解決辦法然而中斷應用程序?你知道如何使用這些數據嗎? – Paddy 2010-05-20 13:37:32
重命名錶並將其替換爲執行'SELECT TOP x * FROM new_name_of_the_table'的視圖。但是請注意,應用程序執行的數據操作(INSERT,UPDATE,DELETE)將會失敗。 – Heinzi 2010-05-20 13:41:03
@Heinzi很遺憾,我們需要能夠插入,更新和刪除。 – tplaner 2010-05-20 13:43:27