我有這個,我在設定的總數上得到一個錯誤。 爲什麼我不能多次訪問cte?多次使用一個CTE
ALTER PROCEDURE [dbo].[GetLeaguePlayers]
(
@idleague int,
@pageNumber int,
@pageSize int,
@total int OUTPUT
)
AS
WITH CTEPlayers AS
(
SELECT ROW_NUMBER() OVER (ORDER BY p.Name) AS RowNumber, p.Id, p.Name, t.Name AS Team
FROM Players p INNER JOIN Teams t ON p.IdTeam=t.Id INNER JOIN Leagues l ON l.Id=t.IdLeague
WHERE [email protected]
)
SELECT Id, Name
FROM CTEPlayers c
WHERE RowNumber>@pageSize*(@pageNumber-1) AND RowNumber<@pageSize*@pageNumber;
SET @total = (SELECT COUNT(*) FROM CTEPlayers)
不!請不要**改變你的問題!去問另一個。 – RBarryYoung 2012-04-17 18:34:28
我的錯誤,我很抱歉 – gigi 2012-04-17 18:35:10