Jump to content


Photo

LIMIT for MSSQL?


  • Please log in to reply
2 replies to this topic

#1 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 April 2006 - 12:09 PM

I know you can use the LIMIT clause in MySQL to grab a specific group of records from a MySQL table, but I'm using MSSQL and I need to do the same thing. I know about the TOP function, but I'm not sure how to go about grabbing the TOP x records starting at record y.

I have groups of 12000+ records in a table and I'm graphing all the records. They will have the option to zoom in on the graph and I need to be able to go back and grab from x to y.

Any ideas? The only other thing I was thinking of was doing some math on the ID value (auto-increment).

Info: PHP Manual


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 April 2006 - 12:19 PM

Just in case anyone else ever digs this thread back up or searches for it, I did find an answer:

[a href=\"http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=850&lngWId=5\" target=\"_blank\"]http://www.planet-source-code.com/vb/scrip...Id=850&lngWId=5[/a]

I modified it to fit my application and it works like a charm. Obviously it's very bloated compared to the LIMIT clause, but it works.

Info: PHP Manual


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 28 April 2006 - 01:50 PM

Also to emulate LIMIT 20,10

SELECT TOP 10 * FROM mssqltable
WHERE id NOT IN (SELECT TOP 20 id FROM mssqltable)

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users