sql >> Base de Datos >  >> RDS >> Sqlserver

Equivalente de LIMIT en T-SQL

Sql Server 2005 no tiene la sintaxis límite que tiene arriba, que no se agregó hasta 2012. Querrá usar la cláusula OVER y las expresiones de tabla comunes.

Ejemplo de SqlTeam

WITH Members  AS
(
    SELECT  M_NAME, M_POSTS, M_LASTPOSTDATE, M_LASTHEREDATE, M_DATE, M_COUNTRY,
            ROW_NUMBER() OVER (ORDER BY M_POSTS DESC) AS RowNumber
    FROM    dbo.FORUM_MEMBERS
)
SELECT  RowNumber, M_NAME, M_POSTS, M_LASTPOSTDATE, M_LASTHEREDATE, M_DATE, M_COUNTRY
FROM    Members
WHERE   RowNumber BETWEEN 1 AND 20
ORDER BY RowNumber ASC;