Skip to content

Instantly share code, notes, and snippets.

@thanley11
Created August 25, 2015 20:00
Show Gist options
  • Save thanley11/fc267d28ae3c5476e06b to your computer and use it in GitHub Desktop.
Save thanley11/fc267d28ae3c5476e06b to your computer and use it in GitHub Desktop.
USE [db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[load_pids]
@Skip AS INT,
@Take AS int
AS
BEGIN
SELECT * FROM (
SELECT COUNT(mt.pid) OVER() [TotalRows], ROW_NUMBER() OVER(ORDER BY mt.prid) AS [RowNum], mt.pid, mt.repo_name
from db.dbo.mytable mt
) AS [InsideQuery]
WHERE [RowNum] BETWEEN (@Skip * @Take) + 1 AND (@Skip + 1) * @Take
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment