Welcome, Guest. Please login or register.
September 05, 2010, 02:13:42 am
Home Help Search Calendar Login Register
Programming Forum
Get answers from expert developers
progx.us - Mobility solutions for business

+  Programming forum
|-+  Software Programming
| |-+  Database Development
| | |-+  MS SQL
| | | |-+  Get rows from any middle part of table SQL.
« previous next »
Pages: [1] Print
Author Topic: Get rows from any middle part of table SQL.  (Read 161 times)
jeter
Newbie
*
Posts: 5


View Profile Email
« on: July 12, 2010, 01:45:41 pm »

Hi Sir
I have table with 1000 records.I need a way
to get records from 60 to 250
80-600 and so on is it possible on ms sql and how todo this.
Logged
Tigran
http://www.progx.us
Administrator
Newbie
*****
Posts: 29



View Profile WWW Email
« Reply #1 on: July 12, 2010, 01:52:28 pm »

Ok its possible if you use MS sql 2005 or higher.
Let see example
with table "Mytable".Sorted by "Name" Column .
--------------------
Name
column1
column2
here is the code for stored procedure.

Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



-- =============================================
-- Author: Tigran Sargsyan
-- Create date: 25.06.2009
-- Description: gets GetAddressById by Id
-- =============================================
Create PROCEDURE [dbo].[GetRowsFromCustomParts]
-- Add the parameters for the stored procedure here
@From int,
@TO int

AS
BEGIN

WITH cnx AS

(
SELECT *, ROW_NUMBER() OVER(ORDER BY Name) AS idx
FROM Mytable
)
SELECT * FROM cnx WHERE idx BETWEEN @From AND @TO
end

Logged

working hard to make word smarter
Global software development
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC | Software Application Development