Anuj Tripathi Mothers are those wonderful people who can get up in the morning before the smell of coffee.
SELECT
Name,sum(Qty) as TotalQty FROM Customer
WHERE CustOrderID = @CustOrderID
GROUP BY Name
ORDER BY Name
Here I would get the Various Names of customer with their SUm of product Quantity.
Now, To convert the same in XQUERY I used the following Code:
VB.NET:
Dim dsCAQuanity As New DataSet()
Dim dsTemp As New DataSet
Dim dsCKT As New DataSet
Dim dtCKT As New DataTable
Dim drCKT As DataRow
Dim dcCkt(0) As DataColumn
dcCkt(0) = New DataColumn("Name", GetType(String))
dtCKT.Columns.Add(dcCkt(0))
dtCKT.PrimaryKey = dcCkt
dtCKT.Columns.Add("TotalQty", GetType(String))
query = "(document(""Doc"")//Table)[CustOrderID=""" & CustOrderID & """ ]"
dsCKT = xmlXqury.ReadXMLFile("C:XMLDatabaseCustomer", query)
For Each rowCkt As DataRow In dsCKT.Tables(0).Rows
query =
"LET $doc := (document(""Doc"")//Table)[Name='" & rowCkt("Name") & "' and CustOrderID=""" & CustOrderID & """ ] return <qty> { sum($doc/Qty)} </qty>"dsTemp =
New DataSetdsTemp = xmlXqury.ReadXMLFile("C:XMLDatabaseCustomer", query)
If dsTemp.Tables.Count > 0 Then
If dsTemp.Tables(0).Rows.Count > 0 And dtCKT.Rows.IndexOf(dtCKT.Rows.Find(rowCkt("Name").ToString)) < 0 Then
drCKT = dtCKT.NewRow
drCKT(
"Name") = rowCkt("Name")drCKT(
"TotalQty") = dsTemp.Tables(0).Rows(0)(0)dtCKT.Rows.Add(drCKT)
End If
End If
Next
dsCAQuanity =
New DataSet()dsCAQuanity.Tables.Add(dtCKT)
C#:
DataSet dsCAQuanity = new DataSet();
DataSet dsTemp = new DataSet();
DataSet dsCKT = new DataSet();
DataTable dtCKT = new DataTable();
DataRow drCKT = default(DataRow);
DataColumn[] dcCkt = new DataColumn[1];
dcCkt(0) = new DataColumn("Name", typeof(string));
dtCKT.Columns.Add(dcCkt(0));
dtCKT.PrimaryKey = dcCkt;
dtCKT.Columns.Add("TotalQty", typeof(string));
query = "(document("Doc")//Table)[CustOrderID="" + CustOrderID + "" ]";
dsCKT = xmlXqury.ReadXMLFile("C:XMLDatabaseCustomer", query);
foreach (DataRow rowCkt in dsCKT.Tables(0).Rows) {
query = "LET $doc := (document("Doc")//Table)[Name='" + rowCkt("Name") + "' and CustOrderID="" + CustOrderID + "" ] return <qty> { sum($doc/Qty)} </qty>";
dsTemp = new DataSet();
dsTemp = xmlXqury.ReadXMLFile("C:XMLDatabaseCustomer", query);
if (dsTemp.Tables.Count > 0) {
if (dsTemp.Tables(0).Rows.Count > 0 & dtCKT.Rows.IndexOf(dtCKT.Rows.Find(rowCkt("Name").ToString)) < 0) {
drCKT = dtCKT.NewRow;
drCKT("Name") = rowCkt("Name");
drCKT("TotalQty") = dsTemp.Tables(0).Rows(0)(0);
dtCKT.Rows.Add(drCKT);
}
}
}
dsCAQuanity = new DataSet();
dsCAQuanity.Tables.Add(dtCKT);
The data set dsCAQuanity will return the same record as given by the above stored procedure, means it will reterive the record with GROUP BY and ORDER BY clause.
Hope it will sort out your illusion for XQUERY group BY & order by statement. XQUERY provides Order by clause, whcih can also be used with different aspects.
Happy Coding.
- Related Articles
- Related Q&A




The ASP Gauge: More Than The Usual
By: chaudhary fahim | 20/11/2009Digital dashboards often have several displayed gauges showcasing different data being monitored. An ASP gauge is one such type of gauge used on an ASP template page. Digital dashboards are tools which show data being monitored for easy referencing and analysis. In this fast paced world, there is a need for such tools in order to manage huge amounts of data simultaneously.
Drivers Installation With WiX
By: Apriorit | 20/11/2009This article is devoted to the methods of the driver packages installation/uninstallation using WiX. In particular we will discuss the usage of the Microsoft DPInst utility for the installation and removal of the drivers during the Windows Installer package setup, review the principles of DPInst functioning, review the issues with the unsigned drivers installation and learn how to launch multiple MSI installations from already running Windows Installer package setup.
Database design & development in Orange County
By: Mike Nielson | 20/11/2009The database development solutions are designed to provide the integrity of data along with the security of applications. The database systems are required for effective storage of data and management of data so that the information may be utilized in the software applications. Database development takes place in phases, such as analysis performed by the business analysts based on the requirements collected from clients.
Open Source Application: Distribution Terms
By: Tyler Moon | 20/11/2009Open source does not only mean accessing the source code. The distribution terms of open-source software must be in terms and agreement with the source code, free redistribution, derived works etc.
Developing a ColdFusion eCommerce Website Using a Single Database for Multiple Domains with Different Designs Saves Time and Money
By: Jason Luciano | 19/11/2009This article outlines the concept of using Adobe ColdFusion and a single database to dynamically support six or more different website domains with different graphical user interfaces and designs. On an annual basis this project saved the client a countless amount of time and thousands of dollars all while building tremendous market share and product branding recognition simultaneously for all of their websites.
Know about Agile Methodology
By: Pavan Gorakavi | 19/11/2009Agile denote nimbleness. Agile is a light weighted development methodology which is based on iterative development, where solutions evolve from tightly collaborated cross functional teams.
Contrastive analysis of methodologies of test design for functional testing
By: Apriorit | 18/11/2009This article is for those who write or are going to write functional tests for any programs. The goal of this article is to give the flavor of the main techniques of test design and also to answer the question: What method is better to choose for testing your project?
How to put MP4 on iPod?
By: lazerer | 18/11/2009How to put MP4 on iPod? This article will help you convert Video to MP4, put MP4 on iPod, set playlist on iPod, and tell you how to do when iPod MP4 file has no video.
GROUP BY IN XQUERY
By: Anuj Tripathi | 13/11/2009 | ProgrammingThis article will provide you to implement GROUP BY clause in XQUERY with the code.
Creating Sql Database Connection in Asp.net Web Application Through C#
By: Anuj Tripathi | 20/12/2008 | ProgrammingFollowing I am mentioning step-by-step procedure to create database connection to the asp.net website textboxes via C#.
C++ Code for Bus Reservatio System
By: Anuj Tripathi | 20/12/2008 | ProgrammingFollowing code is for Bus reservation system. Coding Done in C++. Just copy paste this code in a text file.Name it bus.cpp, and save this file in your "Turbo C BIN folder". Also You can use Dev C++ and other compilers for C++. Comment it if u like it. If still you have doubt, feel free to ask. Thanks