I have this, and i get an error at set total. Why can\'t i access a cte many times?
ALTER PROCEDURE [dbo].[GetLeaguePlayers]
(
@idleague int,
@pageNu
A CTE is, per definition, only valid for one statement.
You can create an inline table-valued function and then use this as often as you like. The inline function does what the name suggest; its query gets to be part of the query using it (in contrast to non-inline functions which are executed separately and used as a rowset).