IT tutorials
 
Database
 

SQL Server 2012 : Using XML Data - XQuery and FLWOR Operations

2/10/2014 12:40:44 AM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

XQuery is a language that provides the ability to query structured and semi-structured XML data. XQuery is based on the existing XPath query language but includes added support for improved iteration, sorting results, and XML construction.

The real muscle of XQuery comes with the FLWOR operation. FLWOR stands for FOR LET WHERE ORDER BY and RETURN.

The following example is an example of a basic FLWOR query using for and return:

DECLARE @var xml
SET @var = ‘
<Item>
<ItemNumber>V001</ItemNumber>
<ItemNumber>A017</ItemNumber>
</Item>
'

SELECT @var.query('for $item in Item/ItemNumber return $item')

/*
<ItemNumber>V001</ItemNumber>
<ItemNumber>A017</ItemNumber>
*/

where and order by can be specified to filter and sort the output:

DECLARE @var xml
SET @var = ‘
<Item>
<ItemNumber>1010</ItemNumber>
<ItemNumber>1009</ItemNumber>
<ItemNumber>1008</ItemNumber>
<ItemNumber>1007</ItemNumber>
<ItemNumber>1006</ItemNumber>
<ItemNumber>1005</ItemNumber>
<ItemNumber>1004</ItemNumber>
<ItemNumber>1003</ItemNumber>
<ItemNumber>1002</ItemNumber>
<ItemNumber>1001</ItemNumber>
</Item>
'

SELECT @var.query('
for $item in Item/ItemNumber
where $item[.>"1005"]
order by $item
return $item')

<ItemNumber>1006</ItemNumber>
<ItemNumber>1007</ItemNumber>
<ItemNumber>1008</ItemNumber>
<ItemNumber>1009</ItemNumber>
<ItemNumber>1010</ItemNumber>

The where clause filters the XQuery expression for item numbers greater than 1005, and the order by clause orders the nodes in ascending order.

 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.