Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
fabianus76
Posting Yak Master
191 Posts |
Posted - 2006-01-15 : 10:47:45
|
| I know the "top" function to get the first x rows. What I am looking for is how to get row x to y, not starting from the top (for example form 1000 to 2000). Thank you for any advice!Regards,Fabianmy favorit hoster is ASPnix : www.aspnix.com ! |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-15 : 11:04:01
|
| Try the followingselect top 1000 *from (select top 2000 * from Table1 order by id) torder by id descor if u want from any value to any other, have a function to pass ur start & end, create the query dynamically, execute to get the result |
 |
|
|
fabianus76
Posting Yak Master
191 Posts |
Posted - 2006-01-15 : 11:20:43
|
| Hi Srinika, thank you for this. Unfortunatly I do not have an ID in this table. In MySQL you might select row x to y, that's why I though about it.you write : "or if u want from any value to any other, have a function to pass ur start & end, create the query dynamically, execute to get the result" I do not understand - how could I "have a function" ?Regards, Fabianmy favorit hoster is ASPnix : www.aspnix.com ! |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-01-15 : 11:27:44
|
| Without an ID value or some other method of consistently ordering the data, you cannot guarantee getting consistent results even with the TOP clause, let along grabbing a set of records from the middle of the dataset. |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-15 : 12:24:20
|
quote: Originally posted by fabianus76 ... I do not have an ID in this table.....
To get range of records meaningfully (blindman also saying the same) u should have some field in an "order by". U may have some primary key or any field from which u want this records to be sorted when selecting. Use that field. It doesn't have to be the field called "ID"quote: Originally posted by fabianus76 ... you write : "or if u want from any value to any other, have a function to pass ur start & end, create the query dynamically, execute to get the result" I do not understand - how could I "have a function" ?
my any value is, ur x or 1000 in ur examplemy any other is, ur y or 2000 in ur exampleFunction is something that u have to write (UDF)Functions can have parameters, Create the function so as to accept 2 parameters.Get those parameters and write a dynamic SQL queryExecute it.U need to Refer some material, may be Books OnLine and learn it. I can tell u, but u won't learn it, unless doing it urself. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|