{"id":266,"date":"2012-06-26T15:40:00","date_gmt":"2012-06-26T21:40:00","guid":{"rendered":"https:\/\/jackdonnell.com\/?p=266"},"modified":"2015-12-28T16:42:50","modified_gmt":"2015-12-28T22:42:50","slug":"xquery-examples","status":"publish","type":"post","link":"https:\/\/jackdonnell.com\/?p=266","title":{"rendered":"XQUERY &#8211; Examples and Scripts"},"content":{"rendered":"<p>There are tons of thing in this world that I really don&#8217;t understand. SQL Server XQuery is just one of those just out of reach.\u00a0 Poking around trying to answer a question for a developer, I found the following XML script examples. Teh writer provides excellent explanations and examples. Immediately found the right path(pun intended) to go down.\u00a0 I so wished my brain worked this way!<\/p>\n<h2><a href=\"http:\/\/beyondrelational.com\/modules\/2\/blogs\/28\/posts\/10279\/xquery-labs-a-collection-of-xquery-sample-scripts.aspx\" target=\"_blank\">XQuery Labs &#8211; A Collection of XQuery Sample Scripts<\/a><\/h2>\n<p>Jun 26 2008 3:41PM by <a id=\"ctl00_ctl00_bcr_bcr_ctl05_ctl02_postdetails_DynamicPostDetails_postedby\" href=\"http:\/\/beyondrelational.com\/members\/jacobbr\/default.aspx\" target=\"_new\">Jacob Sebastian<\/a><\/p>\n<p><!--more--><\/p>\n<p><strong>XQuery Sample Scripts<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/06\/26\/xquery-lab-1-transforming-rows-to-columns.aspx\">XQuery Lab 1 &#8211; Transforming rows to columns<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/06\/26\/xquery-lab-2-an-example-using-outer-apply.aspx\">XQuery Lab 2 &#8211; An example using OUTER APPLY<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/06\/27\/xquery-lab-3-filtering-specific-nodes.aspx\">XQuery Lab 3 &#8211; Filtering specific nodes<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/06\/27\/xquery-lab-4-joining-xml-nodes-with-a-relational-table.aspx\">XQuery Lab 4 &#8211; Joining XML Nodes with a Relational Table<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/06\/30\/xquery-lab-5-working-with-namespaces.aspx\">XQuery Lab 5 &#8211; Working with Namespaces<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/11\/xquery-lab-6-processing-header-detail-information.aspx\">XQuery Lab 6 &#8211; Processing Header-Detail information<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/11\/xquery-lab-7-extracting-a-comma-separated-list-of-values.aspx\">XQuery Lab 7 &#8211; Extracting a comma separated list of values<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/24\/xquery-lab-8-how-to-update-the-attribute-value-of-an-xml-variable.aspx\">XQuery Lab 8 &#8211; How to update the attribute value of an XML variable?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/25\/xquery-lab-9-how-to-delete-an-attribute-from-an-xml-variable.aspx\">XQuery Lab 9 &#8211; How to delete an attribute from an XML variable?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/25\/xquery-lab-10-how-to-insert-an-attribute-to-an-xml-variable.aspx\">XQuery Lab 10 &#8211; How to insert an attribute to an XML variable<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/25\/xquery-lab-11-how-to-insert-an-element-to-an-xml-variable.aspx\">XQuery Lab 11 &#8211; How to insert an element to an XML variable<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/07\/30\/xquery-lab-12-different-ways-of-reading-values-from-an-xml-variable.aspx\">XQuery Lab 12 &#8211; Different ways of reading values from an XML variable<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/04\/xquery-lab-13-reading-values-from-an-xml-variable.aspx\">XQuery Lab 13 &#8211; Reading values from an XML variable<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/06\/xquery-lab-14-applying-filters-on-multiple-attributes.aspx\">XQuery Lab 14 &#8211; Applying filters on multiple attributes<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/07\/xquery-lab-15-how-to-locate-and-modify-an-attribute-using-a-variable.aspx\">XQuery Lab 15 &#8211; How to locate and modify an attribute using a variable?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/08\/xquery-lab-16-how-to-modify-an-attribute-specified-by-a-variable.aspx\">XQuery Lab 16 &#8211; How to modify an attribute specified by a variable?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/12\/xquery-lab-17-how-to-update-the-value-of-an-element.aspx\">XQuery Lab 17 &#8211; How to update the value of an element<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/13\/xquery-lab-18-how-do-i-delete-an-element-from-an-xml-variable.aspx\">XQuery Lab 18 &#8211; How do I delete an element from an XML variable?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/14\/xquery-lab-19-how-to-parse-a-delimited-string.aspx\">XQuery Lab 19 &#8211; How to parse a delimited string?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/17\/xquery-lab-20-how-to-change-the-position-of-elements-how-to-move-an-element-up-or-down.aspx\">XQuery Lab 20 &#8211; How to change the position of elements &#8211; How to move an element up or down<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/17\/xquery-lab-21-how-to-change-the-position-of-elements-move-an-element-to-a-specific-location.aspx\">XQuery Lab 21 &#8211; How to change the position of elements &#8211; Move an element to a specific location<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/17\/xquery-lab-22-how-to-change-the-position-of-elements-move-an-item-to-a-specific-position.aspx\">XQuery Lab 22 &#8211; How to change the position of elements &#8211; Move an item to a specific position<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/21\/xquery-lab-23-retrieving-values-and-position-of-elements.aspx\">XQuery Lab 23 &#8211; Retrieving values and position of elements<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/08\/26\/xquery-lab-24-reading-value-of-an-element-specified-by-a-variable.aspx\">XQuery Lab 24 &#8211; Reading value of an element specified by a variable<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-25-writing-a-tsql-function-to-compare-two-xml-values-part-1.aspx\">XQuery Lab 25 &#8211; Writing a TSQL Function to compare two XML values (Part 1)<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-26-reading-values-from-elements-using-wildcards.aspx\">XQuery Lab 26 &#8211; Reading values from elements using wildcards<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-27-reading-the-name-of-elements-using-wildcards.aspx\">XQuery Lab 27 &#8211; Reading the name of elements using wildcards<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-28-how-to-find-the-number-of-child-elements-of-an-xml-value.aspx\">XQuery Lab 28 &#8211; How to find the number of child elements of an XML value?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-29-how-to-find-the-number-of-attributes-an-xml-element-has.aspx\">XQuery Lab 29 &#8211; How to find the number of attributes an XML element has?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-30-how-to-read-the-value-of-an-attribute-at-a-given-position.aspx\">XQuery Lab 30 &#8211; How to read the value of an attribute at a given position?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-31-how-to-find-the-name-of-an-attribute-at-a-given-position.aspx\">XQuery Lab 31 &#8211; How to find the name of an attribute at a given position?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-32-how-to-check-the-existence-of-an-attribute-in-an-xml-element.aspx\">XQuery Lab 32 &#8211; How to check the existence of an attribute in an XML element?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-33-how-to-run-a-loop-over-all-the-attributes-of-an-xml-element.aspx\">XQuery Lab 33 &#8211; How to run a loop over all the attributes of an XML element?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-34-how-to-retrieve-the-child-element-at-a-specified-position.aspx\">XQuery Lab 34 &#8211; How to retrieve the child element at a specified position?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-35-how-to-write-a-loop-to-process-all-the-child-elements-of-an-xml-value.aspx\">XQuery Lab 35 &#8211; How to write a loop to process all the child elements of an XML value?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/09\/14\/xquery-lab-36-writing-a-tsql-function-to-compare-two-xml-values-part-2.aspx\">XQuery Lab 36 &#8211; Writing a TSQL Function to compare two XML values (Part 2)<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/10\/11\/xquery-lab-37-working-with-multiple-namespaces.aspx\">XQuery Lab 37 &#8211; Working with multiple namespaces<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2008\/10\/11\/xquery-lab-38-delete-elements-having-date-value-older-than-30-days.aspx\">XQuery Lab 38 &#8211; Delete elements having date value older than 30 days<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/01\/23\/xquery-lab-39-retrieve-fully-qualified-path-of-attributes-and-elements.aspx\">XQuery Lab 39 &#8211; Retrieve Fully qualified path of attributes and elements<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/01\/27\/xquery-lab-40-extracting-words-matching-a-pattern-from-a-varchar-column.aspx\">XQuery Lab 40 &#8211; Extracting words matching a pattern from a varchar column<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/02\/05\/xquery-lab-41-another-string-parsing-example-using-xquery.aspx\">XQuery Lab 41 &#8211; Another string parsing example using XQuery<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/02\/05\/xquery-lab-42-how-to-execute-a-dynamic-openxml-query.aspx\">XQuery Lab 42 &#8211; How to Execute a Dynamic OPENXML() Query?<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/03\/01\/xquery-lab-43-deleting-multiple-elements.aspx\">XQuery Lab 43 &#8211; Deleting multiple elements<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/06\/02\/xquery-lab-44-inserting-an-xml-data-type-variable-to-an-xml-document.aspx\">XQuery Lab 44 \u2013 Inserting an XML fragment into an XML Document<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/07\/31\/xquery-lab-45-delete-a-given-attribute-if-it-is-at-a-specified-position.aspx\">XQuery Lab 45 \u2013 Delete a given attribute if it is at a specified position<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/08\/12\/xquery-lab-46-extracting-zip-code-from-an-address-value.aspx\">XQuery Lab 46 \u2013 Extracting Zip Code from an Address Value<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/08\/19\/xquery-lab-47-generating-html-table-from-xml-data.aspx\">XQuery Lab 47 \u2013 Generating HTML table from XML Data<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/08\/22\/xquery-lab-48-sorting-query-files-in-sql-server-management-studio-ssms-solution-project.aspx\">XQuery Lab 48 &#8211; Sorting Query files in SQL Server Management Studio (SSMS) Solution\/Project<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/08\/26\/xquery-lab-49-deleting-rows-from-a-table-based-on-the-data-in-an-xml-document.aspx\">XQuery Lab 49 \u2013 Deleting rows from a table based on the data in an XML document<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2009\/12\/23\/xquery-lab-50-reading-data-from-google-analytics-atom-feed.aspx\">XQuery Lab 50 \u2013 Reading data from Google Analytics Atom Feed<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/02\/16\/xquery-lab-51-querying-an-rdf-document-using-tsql-and-xquery.aspx\">XQuery Lab 51 \u2013 Querying an RDF document using TSQL and XQuery<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/02\/25\/XQuery-Lab-52-A-More-Intuitive-way-of-reading-an-RDF-document.aspx\">XQuery Lab 52 \u2013 A More Intuitive way of reading an RDF document<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/03\/23\/xquery-lab-53-reading-information-from-sql-server-extended-event-information-xml.aspx\">XQuery Lab 53 \u2013 Reading information from SQL Server Extended Event Information XML<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/03\/31\/xquery-lab-54-modifying-an-xml-document-with-a-select-query.aspx\">XQuery Lab 54 \u2013 Modifying an XML document with a SELECT Query<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/04\/07\/xquery-lab-55-extracting-values-from-xml-elements-that-matches-a-string-pattern.aspx\">XQuery Lab 55 \u2013 Extracting values from XML elements that matches a string pattern<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/06\/09\/xquery-lab-56-inserting-elements-with-unicode-values.aspx\">XQuery Lab 56 \u2013 Inserting elements with UNICODE values<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/06\/17\/xquery-lab-57-getting-started-with-openxml.aspx\">XQuery Lab 57 \u2013 Getting Started with OPENXML<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/05\/30\/select-from-xml.aspx\">XQuery Lab 58 &#8211; SELECT * FROM XML<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/06\/22\/xquery-lab-58-openxml-and-xml-namespace-declarations.aspx\">XQuery Lab 59 \u2013 OPENXML() and XML Namespace Declarations<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/06\/24\/xquery-lab-59-executing-dynamic-query-strings-with-openxml.aspx\">XQuery Lab 60 \u2013 Executing dynamic query strings with OPENXML()<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/06\/29\/xquery-lab-61-writing-a-recursive-cte-to-process-an-xml-document.aspx\">XQuery Lab 61 \u2013 Writing a Recursive CTE to process an XML document<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/07\/01\/xquery-lab-62-revisiting-simple-tsql-select-operations-using-xquery.aspx\">XQuery Lab 62 \u2013 Revisiting simple TSQL SELECT operations using XQuery<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2010\/12\/14\/xquery-lab-63-deleting-empty-elements-from-an-xml-document.aspx\">XQuery Lab 63 \u2013 Deleting empty elements from an XML document<\/a><\/li>\n<li><a href=\"http:\/\/beyondrelational.com\/blogs\/jacob\/archive\/2011\/07\/18\/xquery-lab-64-reading-values-from-an-xml-column.aspx\">XQuery Lab 64 \u2013 Reading values from an XML column<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Tags:\u00a0<\/strong>XQuery-Labs, XML, XQuery, XQuery Functions, SQL Server XQuery, XQuery in TSQL, XQuery Training, XQuery Tutorial,<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are tons of thing in this world that I really don&#8217;t understand. SQL Server XQuery is just one of those just out of reach.\u00a0 Poking around trying to answer a question for a developer, I found the following XML &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/jackdonnell.com\/?p=266\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[273,266,138,113,22,351,5,282],"tags":[89,260,356,67,357,249,35,36,295,52,291,355],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-administration","category-dba","category-programming","category-reportingbi","category-sql-server","category-ssms","category-t-sql","category-xml","tag-design","tag-developer","tag-functions","tag-how-to","tag-openxml","tag-script","tag-select","tag-sql","tag-sql-server","tag-ssms","tag-t-sql","tag-xml"],"_links":{"self":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266"}],"version-history":[{"count":7,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":524,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions\/524"}],"wp:attachment":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}