Forum Moderators: open

Message Too Old, No Replies

How to return a certain set of records from a table in MSSQL

A conversion between a MYSQL and MSSQL query would be useful!

         

bhonda

10:54 am on Mar 10, 2006 (gmt 0)

10+ Year Member



Hey there...

Got myself in a little pickle, and I'm running the risk of spending far too much time trying to figure this out on my own, so I thought I'd call in the troops (you guys!).

Here's the scene...in my database I've got a HUGE list of data. Basically, I need to be able to return the records between rows/records #5 and #10 (for example) with an sql (MS server 2000) query. I know in MYSQL you can use LIMIT x,y, which would be perfect for what I need, but I get the impression this isn't used in MSSQL? Maybe I'm wrong...but has anyone got any suggestions? I've thought about using TOP x, but that kinda defeats the object of what I need...I can only return the records I want.

I know this may seem a strange way to so something, but it's an odd solution to an odd problem!

Any help would be greatly appreciated...if anyone needs any further details please feel free to ask!

Cheers,

B

FalseDawn

12:20 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



There's no LIMIT in MS SQL, but workarounds, for example see here:

http: //www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=850&lngWId=5

or something like:

SELECT TOP 20 * FROM table where id_col NOT IN (SELECT TOP 10 id_col FROM table)

for LIMIT 10,20

bhonda

12:37 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



That's absolutely spot on! Exactly what I'm looking for - cheers!

B