tonyhhisc
asked on
LIMIT FOR MSSQL
we have this query for search ..
$query = " SELECT * FROM dbo.Rooms WHERE ROOMNO NOT IN (SELECT DISTINCT S_ROOMNO FROM dbo.Stay WHERE ((S_ADATE BETWEEN '$CheckIn' AND '$CheckOut') AND (S_DDATE BETWEEN '$CheckIn' AND '$CheckOut')) OR (S_ADATE < '$CheckIn' AND S_DDATE > '$CheckOut') OR (S_ADATE < '$CheckIn' AND ( S_DDATE BETWEEN '$CheckIn' AND '$CheckOut')) OR (( S_ADATE BETWEEN '$CheckIn' AND '$CheckOut' ) AND S_DDATE > '$CheckOut')) ";
after fetch result we need to add this pagination.
$offset = ($currentpage - 1) * $rowsperpage + 1;
$limit=($offset-1) + $rowsperpage;
$query .= "LIMIT $offset , $limit";
but this LIMIT is not working with MSSQL Server , it works for Mysql but i don't know how to do it in MSSQL to work with PHP.
Any help is greatly appreciated!!
Tony
$query = " SELECT * FROM dbo.Rooms WHERE ROOMNO NOT IN (SELECT DISTINCT S_ROOMNO FROM dbo.Stay WHERE ((S_ADATE BETWEEN '$CheckIn' AND '$CheckOut') AND (S_DDATE BETWEEN '$CheckIn' AND '$CheckOut')) OR (S_ADATE < '$CheckIn' AND S_DDATE > '$CheckOut') OR (S_ADATE < '$CheckIn' AND ( S_DDATE BETWEEN '$CheckIn' AND '$CheckOut')) OR (( S_ADATE BETWEEN '$CheckIn' AND '$CheckOut' ) AND S_DDATE > '$CheckOut')) ";
after fetch result we need to add this pagination.
$offset = ($currentpage - 1) * $rowsperpage + 1;
$limit=($offset-1) + $rowsperpage;
$query .= "LIMIT $offset , $limit";
but this LIMIT is not working with MSSQL Server , it works for Mysql but i don't know how to do it in MSSQL to work with PHP.
Any help is greatly appreciated!!
Tony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no work with meWhat, exactly, happened? Did you get any output at all? Did you get an error message? If you can give us the SSCCE or at least some clues to go on we might be able to produce better answers.
I believe that MSSQL has a TOP clause. There is some discussion of this here:
http://forums.asp.net/t/1224860.aspx?SELECT+TOP+MSSQL
There is also OFFSET / FETCH.
http://technet.microsoft.com/en-us/library/gg699618.aspx
ASKER
thanks for your help.
ASKER
KInd regards,