0

I'm confused when first met with the problem of using LIMIT clause in MSSQL. Can't get it how to make the pagination script work.

I want to use LIMIT clause with extra WHERE and ORDERY BY conditions. Any help is welcome!

This is my MySQL query:

$query = mysql_query("SELECT FLD_NAME, FLD_AGE FROM TBL_USERS WHERE FLAG='1' ORDER BY FLD_AGE DESC LIMIT 0,50");

//rows_per_page = 50;

How can I convert this MySQL query to the MSSQL query?

Thanks in advance!

ilnur777
  • 1,135
  • 5
  • 16
  • 28

3 Answers3

5

For full pagination, you can use the ROW_NUMBER() function somewhat like:

select * from 
(select Row_Number() over ( ORDER BY FLD_AGE DESC ) as RowIndex, FLD_NAME, FLD_AGE FROM    
TBL_USERS WHERE FLAG='1') as pager    Where pager.RowIndex >= 10 and pager.RowIndex < 40
Ben Schwehn
  • 4,505
  • 1
  • 27
  • 45
1
SELECT TOP(50) FLD_NAME, FLD_AGE FROM TBL_USERS WHERE FLAG='1' ORDER BY FLD_AGE DESC 

For full pagination sample check Google!

sumek
  • 26,495
  • 13
  • 56
  • 75
0
SELECT TOP 50 FLD_NAME,FLD_AGE
FROM TBL_USERS
WHERE FLAG='1'
ORDER BY FLD_AGE DESC;

For more information, visit MSDN and MSDN again

JClaspill
  • 1,725
  • 19
  • 29