| Author |
Topic |
|
maya13
Starting Member
4 Posts |
Posted - 2008-09-22 : 09:25:33
|
Hi All,I have some table, lets say PRODUCTS table, with a unique identifier.I would like to write a store proc which recieves the parameters fromRec and toRec and returns the records from row number fromRec to row number toRec.Does someone can help me?Thanks... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 09:28:10
|
| [code]CREATE PROCEDURE GetRecords@FromRec int@ToRec intASSELECTFROM(SELECT ROW_NUMBER() OVER(ORDER BY uniqueidentifiercolumn) AS Seq,*FROM PRODUCTS)tWHERE t.Seq BETWEEN @FromRec AND @ToRecGO[/code] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-22 : 10:15:34
|
How do you define your range of records? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
maya13
Starting Member
4 Posts |
Posted - 2008-09-23 : 02:03:12
|
Thanks Visakh16 , I'll try it.Peso, I define the range from my code (c#). My table is very big, so I want each time to get for example 10 records. In the beginning records 1-10, then records 11-20 and so on.Maya |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-23 : 02:26:32
|
| Also search for PaginationMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 02:50:04
|
quote: Originally posted by maya13 Thanks Visakh16 , I'll try it.Peso, I define the range from my code (c#). My table is very big, so I want each time to get for example 10 records. In the beginning records 1-10, then records 11-20 and so on.Maya
then what you want is thisCREATE PROCEDURE GetRecords@PageNo int@PageSize intASSELECTFROM(SELECT ROW_NUMBER() OVER(ORDER BY uniqueidentifiercolumn) AS Seq,*FROM PRODUCTS)tWHERE t.Seq BETWEEN ((@PageNo-1)*@PageSize)+1 AND (@pageNo * @PageSize)GO and pass pageno=1,2,... to get corresponding page recordsand for above examle put @pageSize=10, you can vary page size by passing other values also. |
 |
|
|
maya13
Starting Member
4 Posts |
Posted - 2008-09-23 : 03:18:03
|
Thank you very much   !!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 03:20:05
|
quote: Originally posted by maya13 Thank you very much   !!!
welcome |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-23 : 07:18:58
|
Or thisCREATE PROCEDURE dbo.uspGetRecords( @PageNo INT, @PageSize INT)ASSELECT TOP (@PageSize) NumberFROM ( SELECT TOP (@PageNo * @PageSize) Number FROM master..spt_values WHERE Type = 'P' ORDER BY Number ) AS dORDER BY Number DESC E 12°55'05.63"N 56°04'39.26" |
 |
|
|
maya13
Starting Member
4 Posts |
Posted - 2008-09-23 : 07:52:48
|
| Thanks !!! |
 |
|
|
|