Help with optimizing query | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Help with optimizing query

Hi, i was wondering whether some SQL expert would be willing to take a look at this query for me. It is a search query that is frequently used on our site so it needs to perform great. The query handles PAGING on the website, so everytime i need to get the total count of rows based on the search parameters, and then i have to select the rows in the current PageIndex (based on specified pageSize). To get the total rows in the first query select them into a variable, like this: @totalPropertiesCount = COUNT(id) First of, i have a problem with getting the total COUNT of rows when using the following (in query number 2): SELECT TOP 200
ROW_NUMBER() OVER (ORDER BY id ASC) AS row… So for the time being i need select the content TWICE, once to get the total count, and then again to get rows based on the current pageIndex (so obviously the query needs some tuning). Let me know if you want me to paste the whole query into the thread. Thanks and regards,
Have you checked out these liks? — SQL Server 2005 — SQL Server 2000 — SQL Server 2000 Gaurav
The views expressed here are those of the author and no one else. There are no warranties as to the reliability or accuracy of anything presented here.

Also refer Madhivanan Failing to plan is Planning to fail
Thanks a lot for the quick reply guys!
Those links were a great help! Bjorn.