473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to page SQL query result returned from FOR XML statement?

Gurus.
I do not know if it is possible, but here is what I want to do.
I want to allow user to page the SQL result, so he could decides to
return from row 10 to row 20, or row 100 to 200, without returns the
whole resultset. Every time he sends another request, I do not mind to
hit the database again, (I do not want to cache the result in the
middle tier server, scalability issue), and I know that I could achieve
this with CURSOR, but unfortunately the FOR XML is not allowed in a
CURSOR statement .
(I know that I could achieve what I want to do by writing custom code
in the middle tier, but I just want to see if there is a way to do this
on the database side.)

Any comments & suggestion is greatly appreciated.
Thanks in advance.

(I am using SQL2005)

John

Apr 25 '06 #1
2 1251
John (jo*****@yahoo.com) writes:
I do not know if it is possible, but here is what I want to do.
I want to allow user to page the SQL result, so he could decides to
return from row 10 to row 20, or row 100 to 200, without returns the
whole resultset. Every time he sends another request, I do not mind to
hit the database again, (I do not want to cache the result in the
middle tier server, scalability issue), and I know that I could achieve
this with CURSOR, but unfortunately the FOR XML is not allowed in a
CURSOR statement .
(I know that I could achieve what I want to do by writing custom code
in the middle tier, but I just want to see if there is a way to do this
on the database side.)

Any comments & suggestion is greatly appreciated.
Thanks in advance.

(I am using SQL2005)


If you are on SQL 2005, I would suggest that you lool into the
row_number function. Here is a sample:

SELECT OrderID, OrderDate, CustomerID
FROM (SELECT OrderID, OrderDate, CustomerID,
rowno = row_number() OVER (ORDER BY OrderID)
FROM Northwind..Orders) AS a
WHERE rowno BETWEEN 100 AND 200
FOR XML AUTO

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 25 '06 #2
Check the following articles:

http://weblogs.asp.net/Firoz/archive...12/411949.aspx

http://sqljunkies.com/WebLog/amachan...1/03/4945.aspx

http://www.sqlmag.com/articles/index...ticleid=43922&

I use a tweaked version as shown in Itzik's article with sorting and
filtering. The only caveat is that is uses dynamic sql. With SQL 2005
you have a few more options to manage permissions for these type of
stored procedures. SQL Server MVP Erland has a very good article on
this topic:

http://www.sommarskog.se/grantperm.html

HTH.

Apr 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
3
by: visionstate | last post by:
Hi All, I have used the following article to help me build a query 'on the fly': http://www.fontstuff.com/access/acctut17.htm It's a very useful article and is exactly what I was looking for to...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
5
by: th1982 | last post by:
HI All I have a search page' s result which view 3results/per page,but my "next" link to view next page is not working. Here is my code : <?php // Get the search variable from URL ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.