﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / XML </title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 24 May 2012 12:16:57 GMT</lastBuildDate><ttl>20</ttl><item><title>Shredding the query plan XML and then joining that to the individual query</title><link>http://www.sqlservercentral.com/Forums/Topic1306043-21-1.aspx</link><description>Hi allI want to add something to a stored procedure plan/stats query I am working on.  I want to list the parameters which were used to compile each statement in a stored procedure.So i am running the below query to examine the XML in the query plan.  Where a stored proc i am examining has more than one statement, i only want the parameters for that statement.The only way i can see of doing this is to join the sys.dm_exec_query_stats column "query_plan_hash" to the shredded equivalent in the query plan: there is an attribute called @QueryPlanHash (/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/QueryPlan/ParameterList/ColumnReference)I was quite pleased with this approach!  But the join doesn't work because i cannot cast the query plan XML's representation of @QueryPlanHash to binary(8), which is the data type of sys.dm_exec_query_stats column.query_plan_hash.  This returns a NULL value from the SQLXML Value function.  And I can't work out if i can do anything with the varchar value that i am able to get back from Value, in terms of casting that to a binary(8) on the TSQL side.  That doesn't seem to work.Needless to say if i have no join at all, i get a cartesian product - each statement is repeated N times, where N is the number of statements in the query plan.  Each statement's parameter list is repeated for each statement.Please see query below, i hope this will explain better what i am trying to do.If anyone knows how i can cast @QueryPlanHash from the XML in such a way that it can join to sys.dm_exec_query_stats column.query_plan_hash, i'd be grateful to know it.  Whether that's a CAST in the XML query or a CAST on the TSQL side, either way that would be great!Or perhaps someone has found a more appropriate way to tie an individual sql statement's parameters (or other part of ITS own portion of the overall plan for the batch or SP) to the query's row in sys.dm_exec_query_stats?  If so, again i'd be very grateful to hear about it.Many thanks for reading and any help you are able to provide.James[code="sql"]WITH XMLNAMESPACES (DEFAULT 'http://schemas.microsoft.com/sqlserver/2004/07/showplan') SELECT 	DB_NAME(qp.dbid) as 'database_name',	REPLACE(SUBSTRING(st.text, PATINDEX('%CREATE %PROCEDURE%', st.text), 100), CHAR(13) + CHAR(10), ' ') 'Stored Procedure Name',	REPLACE(		SUBSTRING(			st.text		,	(qs.statement_start_offset/2) + 1		,	((case qs.statement_end_offset when -1 then datalength(text) else qs.statement_end_offset end - qs.statement_start_offset)/2) + 1		)	,	CHAR(13) + CHAR(10)	, ' ') as 'Statement_text',	qs.creation_time,	qs.last_execution_time,	qs.execution_count-- THESE ARE THE 2 COLUMNS I AM TRYING TO JOIN,	N.c.value('@QueryPlanHash', 'varchar(128)') 'QueryPlanHash' ,	qs.query_plan_hash-- THIS IS WHAT THIS PROBLEM IS ALL ABOUT - GETTING A SPECIFIC PARAMETER OR A LIST OF THEM (IN XML),	N.c.value('QueryPlan[1]/ParameterList[1]/ColumnReference[attribute::Column="@ip_FirmCode"][1]/@ParameterCompiledValue', 'varchar(128)') 'Firm_code_compiled_for',	N.c.query('QueryPlan/ParameterList/ColumnReference') 'All_params',	qs.total_worker_time/1000 AS [Total CPU Time milliseconds],	qs.total_worker_time/execution_count/1000 AS [Avg CPU Time milliseconds],	qs.total_elapsed_time/1000 [Total duration milliseconds],	qs.total_elapsed_time/execution_count/1000 [Avg duration milliseconds],	qs.plan_handle,	qp.query_planFROM sys.dm_exec_query_stats AS qsCROSS APPLY 	sys.dm_exec_sql_text(qs.sql_handle) AS stCROSS APPLY 	sys.dm_exec_query_plan(qs.plan_handle) as qpOUTER APPLY	qp.query_plan.nodes('/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple') as N(c)	WHERE  	st.text like '%create%procedure%_jm_p_DBA_QueryPlanParamsTest_s%'		and not (st.text like '%sys.dm_exec_query_stats%' or st.text like '%dm_exec_cached_plans%' or st.text like '%s_OptimiseExecutionPlans_u%')--	HERE IS THE ATTEMPTED JOIN, NONE OF THE 3 ATTEMPTED JOINS WORK (NO ROWS RETURNED) AND NO JOIN MEANS CARTESIAN PRODUCT, I.E. I DON'T GET THE PARAMS JUST FOR THE --	INDIVIDUAL STATEMENT	--and qs.query_plan_hash = N.c.value('@QueryPlanHash', 'VARCHAR(128)') 	--and qs.query_plan_hash = N.c.value('@QueryPlanHash', 'BINARY(8)') 		and qs.query_plan_hash = CAST(N.c.value('@QueryPlanHash', 'varchar(128)') AS BINARY(8))[/code]</description><pubDate>Thu, 24 May 2012 12:05:08 GMT</pubDate><dc:creator>jmanly</dc:creator></item><item><title>XSLT CODE USING Muenchain Grouping (Very very Urgent)</title><link>http://www.sqlservercentral.com/Forums/Topic1302211-21-1.aspx</link><description>Hi all , I'm a SQL Guy but i was asked to look into this following java script .js file and xslt code. Currently i have performance issue with my xslt code.Let me explain you everthing in detail. I have a .js file when i double click .js file it will take the .csv in that folder and uses the xslt and gives me an .xml output file. For better understanding of the requirement please do the following../* code for my .js file */ (Please copy this to note pad and save it as InvoiceAdjustment.js) [code="plain"]showAbsolutePath("InvoiceAdjustment.js");function showAbsolutePath(path){   var fso = new ActiveXObject("Scripting.FileSystemObject");   var s = "";   s += fso.GetAbsolutePathName(path);      var foldername = s.substring(0,s.indexOf(path,0));   showFolderFileList(foldername);}function showFolderFileList(foldername){   var fso, f, fc, filename;      fso = new ActiveXObject("Scripting.FileSystemObject");   f = fso.GetFolder(foldername);   fc = new Enumerator(f.files);      for (; !fc.atEnd(); fc.moveNext())   {      filename = "";      filename += fc.item();            if (filename.slice(-4) == ".csv")      {        convertCSVtoXML(foldername, filename);      }   }        fso = null;}function  convertCSVtoXML(foldername, filename){   var objDOMDocument = new ActiveXObject("MSXML2.DOM&amp;#100;ocument.4.0");   objDOM&amp;#100;ocument.async = false;     //Create Header  objDOM&amp;#100;ocument.appendChild(XMLHeader(objDOMDocument));   var objXMLDOMNode = objDOM&amp;#100;ocument.documentElement.selectSingleNode("//Document");    // Declare XML object -- this makes it easier to pass as a parameter   var objXML  = new Object();     // Open the extracted csv from zip file  var fso = new ActiveXObject("Scripting.FileSystemObject");    var csvFilename = filename;    var tso = fso.OpenTextFile(csvFilename, 1);   var strInput;     // Loop through the file   while(!tso.AtEndOfStream)    {     strInput = tso.ReadLine();        var vInputLine = strInput.split(",");     objXML.a = vInputLine[0];    objXML.b = vInputLine[1];    objXML.c = vInputLine[2];    objXML.d = vInputLine[3];    objXML.e = vInputLine[4];                        if (objXML.a != 'RebateInvoiceID')    {    objXMLDOMNode.appendChild(XMLFileNode(objDOMDocument,objXML));    }      }   tso.Close();    // Load Transform file  var TransformXSL = new ActiveXObject("MSXML2.DOM&amp;#100;ocument.4.0");  TransformXSL.async = false    TransformXSL.load(foldername + "\\InvAdj.xsl");    // Load XML file and transform it  var TempStagingDoc = new ActiveXObject("MSXML2.DOM&amp;#100;ocument.4.0");  TempStagingDoc.async = false;   TempStagingDoc.loadXML(objDOM&amp;#100;ocument.xml);        var FinalStr = TempStagingDoc.transformNode(TransformXSL);    // Grab just the file name minus any extension  var fn = filename.substring(0, filename.indexOf(".csv"));   tmpxml = fn + ".xml";      // Write out the transformed file. If writing out just the xml file before transform  //  FSObject.WriteLine(objDOM&amp;#100;ocument.xml);         var FSObject = fso.CreateTextFile(tmpxml, true);  FSObject.WriteLine(FinalStr);  FSObject.Close();  /*  // Create empty .flag file then rename it  tmpxml += ".flag";  var fsoEmptyFile = fso.CreateTextFile(tmpxml, true);  fsoEmptyFile.Close();    // Rename the .flag file to .done  var donefilename = tmpxml.substring(0,tmpxml.indexOf(".flag",0));  donefilename += ".done";  fso.MoveFile(tmpxml, donefilename);    // Delete the corresponding .csv file  fso.DeleteFile(csvFilename);  */  // Clear all objects  objDOMDocument = null;   fso = null;  TransformXSL = null;  objXML = null;  TempStagingDoc = null;}function XMLHeader(objDOMDocument){   var XMLHead;  XMLHead = objDOM&amp;#100;ocument.createNode(1, "Document","");     var objXMLDOMAttribute = objDOM&amp;#100;ocument.createAttribute("Version");   objXMLDOMAttribute.text = "1.0";  XMLHead.attributes.setNamedItem(objXMLDOMAttribute);    var objXMLDOMAttribute = objDOM&amp;#100;ocument.createAttribute("CreationTimestamp");   objXMLDOMAttribute.text = getTimestamp();  XMLHead.attributes.setNamedItem(objXMLDOMAttribute);    return(XMLHead);} function XMLFileNode(objDOMDocument,objXML){       var objXMLDOMNode = objDOM&amp;#100;ocument.createNode(1, "RawXMLRow","");    objXMLDOMElement = objDOM&amp;#100;ocument.createElement("RebateInvoiceID");   objXMLDOMElement.text = objXML.a;  objXMLDOMNode.appendChild(objXMLDOMElement);      objXMLDOMElement = objDOM&amp;#100;ocument.createElement("RebateEventID");   objXMLDOMElement.text = objXML.b;  objXMLDOMNode.appendChild(objXMLDOMElement);        objXMLDOMElement = objDOM&amp;#100;ocument.createElement("BusinessUnitCode");   function getBusinessUnitCode(){    var r = String(objXML.c).length;    if(r == 4)    return String(objXML.c);    if( r == 3)  	  return "0"+String(objXML.c);  	  if(r == 2){  		  	  return "00"+String(objXML.c);  	  }  	  else  		  	  return "000"+String(objXML.c);    }  objXMLDOMElement.text = getBusinessUnitCode();   objXMLDOMNode.appendChild(objXMLDOMElement);      objXMLDOMElement = objDOM&amp;#100;ocument.createElement("CategoryID");   objXMLDOMElement.text = objXML.d;  objXMLDOMNode.appendChild(objXMLDOMElement);    objXMLDOMElement = objDOM&amp;#100;ocument.createElement("PaymentAmount");   objXMLDOMElement.text = objXML.e;  objXMLDOMNode.appendChild(objXMLDOMElement);      return(objXMLDOMNode);}function getTimestamp(){  var d = new Date();  var mm = padZeros(d.getMonth()+1);  var dd = padZeros(d.getDate());  var hh = padZeros(d.getHours());  var mn = padZeros(d.getMinutes());  var ss = padZeros(d.getSeconds());    return d.getFullYear()+"-"+ mm +"-"+ dd +"T"+ hh +":"+ mm +":"+ ss;}function padZeros(s){  if (s &amp;lt; 10)  {    s = "0" + s;  }  return(s);}function getDate(stringDate){  var a = String(stringDate).split( "/" );  var strXML ;  strDate = "" ;  for ( var i = 0 ; i &amp;lt; a.length; i++ )   {     if (a[i].length == 1)         strDate += "0" + a[i];     else         strDate += a[i];   }  strDate += "" ;  return strDate;}[/code]/* code for xslt */ ( make an xslt using below code and save it as InvAdj.xsl)[code="xml"]&amp;lt;?xml version="1.0"?&amp;gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:script="script" exclude-result-prefixes="msxsl"&amp;gt;  &amp;lt;xsl:output omit-xml-declaration="yes"/&amp;gt;  &amp;lt;!-- ROOT --&amp;gt;  &amp;lt;xsl:template match="/"&amp;gt;    &amp;lt;EnterpriseDocument&amp;gt;      &amp;lt;xsl:attribute name="InterfaceName"&amp;gt;RebateInvoiceAdjustmentImport&amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:attribute name="ClientID"&amp;gt;        &amp;lt;xsl:choose&amp;gt;          &amp;lt;xsl:when test="normalize-space(ClientID)"&amp;gt;            &amp;lt;xsl:value-of select="//Document/RawXMLRow/ClientID"/&amp;gt;          &amp;lt;/xsl:when&amp;gt;          &amp;lt;xsl:otherwise&amp;gt;1000001&amp;lt;/xsl:otherwise&amp;gt;        &amp;lt;/xsl:choose&amp;gt;      &amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:attribute name="ClientName"&amp;gt;XXXX&amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:attribute name="Version"&amp;gt;1.0&amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:attribute name="CreationSource"&amp;gt;File&amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:attribute name="CreationTimestamp"&amp;gt;        &amp;lt;xsl:value-of select="script:getTimestamp()"/&amp;gt;      &amp;lt;/xsl:attribute&amp;gt;      &amp;lt;xsl:call-template name="InvAdjData"/&amp;gt;    &amp;lt;/EnterpriseDocument&amp;gt;  &amp;lt;/xsl:template&amp;gt;  &amp;lt;xsl:template name="InvAdjData"&amp;gt;      &amp;lt;xsl:for-each select="//Document/RawXMLRow[not(RebateInvoiceID=preceding-sibling::RawXMLRow/RebateInvoiceID)]"&amp;gt;        &amp;lt;xsl:sort select="RebateInvoiceID"/&amp;gt;        &amp;lt;RebateInvoice&amp;gt;          &amp;lt;xsl:attribute name="RebateInvoiceID"&amp;gt;            &amp;lt;xsl:value-of select="RebateInvoiceID"/&amp;gt;          &amp;lt;/xsl:attribute&amp;gt;          &amp;lt;xsl:variable name="InvoiceID"&amp;gt;            &amp;lt;xsl:value-of select="RebateInvoiceID"/&amp;gt;          &amp;lt;/xsl:variable&amp;gt;          &amp;lt;xsl:for-each select="//Document/RawXMLRow[not(RebateEventID=preceding-sibling::RawXMLRow[RebateInvoiceID=$InvoiceID]/RebateEventID)]"&amp;gt;            &amp;lt;xsl:if test="RebateInvoiceID=$InvoiceID"&amp;gt;              &amp;lt;xsl:variable name="EventID"&amp;gt;                &amp;lt;xsl:value-of select="RebateEventID"/&amp;gt;              &amp;lt;/xsl:variable&amp;gt;              &amp;lt;RebateProgram&amp;gt;                &amp;lt;xsl:attribute name="RebateEventID"&amp;gt;                  &amp;lt;xsl:value-of select="RebateEventID"/&amp;gt;                &amp;lt;/xsl:attribute&amp;gt;                &amp;lt;xsl:for-each select="//Document/RawXMLRow[not(BusinessUnitCode=preceding-sibling::RawXMLRow[RebateInvoiceID=$InvoiceID and RebateEventID=$EventID]/BusinessUnitCode)]"&amp;gt;                  &amp;lt;xsl:if test="RebateInvoiceID=$InvoiceID and RebateEventID=$EventID"&amp;gt;                    &amp;lt;xsl:variable name="BUCode"&amp;gt;                      &amp;lt;xsl:value-of select="BusinessUnitCode" /&amp;gt;                    &amp;lt;/xsl:variable&amp;gt;                    &amp;lt;BusinessUnit&amp;gt;                      &amp;lt;xsl:attribute name="BusinessUnitCode"&amp;gt;                      &amp;lt;xsl:value-of select="BusinessUnitCode"/&amp;gt;                    &amp;lt;/xsl:attribute&amp;gt;                      &amp;lt;xsl:for-each select="//Document/RawXMLRow[not(CategoryID=preceding-sibling::RawXMLRow[RebateInvoiceID=$InvoiceID and RebateEventID=$EventID and BusinessUnitCode=$BUCode]/CategoryID)]"&amp;gt;                        &amp;lt;xsl:if test="RebateInvoiceID=$InvoiceID and RebateEventID=$EventID and BusinessUnitCode=$BUCode"&amp;gt;                          &amp;lt;ItemCategoryPayment&amp;gt;                            &amp;lt;xsl:attribute name="CategoryID"&amp;gt;                              &amp;lt;xsl:value-of select="CategoryID"/&amp;gt;                            &amp;lt;/xsl:attribute&amp;gt;                            &amp;lt;xsl:attribute name="PaymentAmount"&amp;gt;                              &amp;lt;xsl:value-of select="PaymentAmount"/&amp;gt;                            &amp;lt;/xsl:attribute&amp;gt;                          &amp;lt;/ItemCategoryPayment&amp;gt;                        &amp;lt;/xsl:if&amp;gt;                      &amp;lt;/xsl:for-each&amp;gt;                    &amp;lt;/BusinessUnit &amp;gt;                    &amp;lt;/xsl:if&amp;gt;                                  &amp;lt;/xsl:for-each&amp;gt;                           &amp;lt;/RebateProgram &amp;gt;            &amp;lt;/xsl:if&amp;gt;          &amp;lt;/xsl:for-each&amp;gt;        &amp;lt;/RebateInvoice &amp;gt;      &amp;lt;/xsl:for-each&amp;gt;  &amp;lt;/xsl:template&amp;gt;  &amp;lt;!-- BEGIN JSCRIPT HELPER CODE, KEEP THIS SECTION AS SMALL AS POSSIBLE IT'S A PERFORMANCE HOG --&amp;gt;  &amp;lt;msxsl:script language="JScript" implements-prefix="script"&amp;gt;    &amp;lt;![CDATA[function getTimestamp(){  var d = new Date();  var m, dy, hr, mn, se;  if (d.getMonth()+1 &amp;lt; 10)  {    m = "0"+(d.getMonth()+1);  }  else if (d.getMonth()+1 &amp;gt; 9)  {    m = d.getMonth()+1;  }  if (d.getDate() &amp;lt; 10)  {    dy = "0"+(d.getDate());  }  else if (d.getDate() &amp;gt; 9)  {    dy = d.getDate();  }  if (d.getHours() &amp;lt; 10)  {    hr = "0"+(d.getHours());  }  else if (d.getHours() &amp;gt; 9)  {    hr = d.getHours();  }  if (d.getMinutes() &amp;lt; 10)  {    mn = "0"+(d.getMinutes());  }  else if (d.getMinutes() &amp;gt; 9)  {    mn = d.getMinutes();  }  if (d.getSeconds() &amp;lt; 10)  {    se = "0"+(d.getSeconds());  }  else if (d.getSeconds() &amp;gt; 9)  {    se = d.getSeconds();  }  return d.getFullYear()+"-"+ m +"-"+ dy +"T"+ hr +":"+ mn +":"+ se;}]]&amp;gt;  &amp;lt;/msxsl:script&amp;gt;&amp;lt;/xsl:stylesheet&amp;gt;[/code]Now copy this records into an excel sheet and save it as .csv  (SAMPLE INPUT)[code="plain"]RebateInvoiceID	RebateEventID	BusinessUnitCode	CategoryID	PaymentAmount1001878	1003042	402	1000057	891001878	1003042	405	1000057	94.421001878	1003043	406	1000057	147.51001878	1003048	423	1000057	97.361001879	1008042	433	1000057	891001879	1008042	434	1000057	70.241001879	1008942	435	1000057	53.081001978	2003042	437	1000057	127.851001978	2003042	438	1000057	180.041001978	3003042	446	1000057	146.611001978	3003042	448	1000057	76.56[/code]Desired output:[code="xml"]- &amp;lt;EnterpriseDocument InterfaceName="RebateInvoiceAdjustmentImport" ClientID="1000001" ClientName="XXXX" Version="1.0" CreationSource="File" CreationTimestamp="2012-05-14T15:33:19" xmlns:script="script"&amp;gt;- &amp;lt;RebateInvoice RebateInvoiceID="1001878"&amp;gt;- &amp;lt;RebateProgram RebateEventID="1003042"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0402"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="89" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0405"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="94.42" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;- &amp;lt;RebateProgram RebateEventID="1003043"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0406"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="147.5" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;- &amp;lt;RebateProgram RebateEventID="1003048"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0423"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="97.36" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;  &amp;lt;/RebateInvoice&amp;gt;- &amp;lt;RebateInvoice RebateInvoiceID="1001879"&amp;gt;- &amp;lt;RebateProgram RebateEventID="1008042"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0433"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="89" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0434"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="70.24" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;- &amp;lt;RebateProgram RebateEventID="1008942"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0435"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="53.08" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;  &amp;lt;/RebateInvoice&amp;gt;- &amp;lt;RebateInvoice RebateInvoiceID="1001978"&amp;gt;- &amp;lt;RebateProgram RebateEventID="2003042"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0437"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="127.85" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0438"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="180.04" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;- &amp;lt;RebateProgram RebateEventID="3003042"&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0446"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="146.61" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;- &amp;lt;BusinessUnit BusinessUnitCode="0448"&amp;gt;  &amp;lt;ItemCategoryPayment CategoryID="1000057" PaymentAmount="76.56" /&amp;gt;   &amp;lt;/BusinessUnit&amp;gt;  &amp;lt;/RebateProgram&amp;gt;  &amp;lt;/RebateInvoice&amp;gt;  &amp;lt;/EnterpriseDocument&amp;gt;[/code]Now place the .csv input file and .js file and xslt in to one folder and double click the .js file it will generate an .xml file. now i need the same result using muenchain grouping method in xslt code. Can you help me please. Thanks.</description><pubDate>Thu, 17 May 2012 17:26:29 GMT</pubDate><dc:creator>sam-1083699</dc:creator></item><item><title>Converting XML to table to be shown in the GUI</title><link>http://www.sqlservercentral.com/Forums/Topic1293656-21-1.aspx</link><description>I have a table as below.CREATE TABLE myResultTable(	RowId IDENTITY(10000,1) NOT NULL,        ItemId INT,	ItemResult [text] NULL,        PRIMARY KEY(Id))ItemResult column will have XML data. XML Schema will be based on ItemId. That means, for each ItemId, ItemResult will follow specific XMLSchema. For eg, the table may contain rows as below.--------------------------------------------------RowId         ItemId            ItemResult---------------------------------------------------1                1                   &amp;lt;Book Id='1'&amp;gt;&amp;lt;Name&amp;gt;BookName&amp;lt;/Name&amp;gt;&amp;lt;/Books&amp;gt;2                2                   &amp;lt;Author Id='1'&amp;gt;&amp;lt;Name&amp;gt;AuthorName&amp;lt;/Name&amp;gt;&amp;lt;/Author&amp;gt;                             3                1                   &amp;lt;Book Id='2'&amp;gt;&amp;lt;Name&amp;gt;BookName1&amp;lt;/Name&amp;gt;&amp;lt;/Book&amp;gt;4                2                    &amp;lt;Author Id='2'&amp;gt;&amp;lt;Name&amp;gt;AuthorName1&amp;lt;/Name&amp;gt;&amp;lt;/Author&amp;gt; ----------------------------------------------------There can be n number of ItemIds, that i dont know during real time. Now my requirement is to write a generic function or stored procedure, which should get ItemId as input and converts all corresponding ItemResults into a table. Given ItemId as 2, I should see table representing all Author information. How would I achieve this?</description><pubDate>Wed, 02 May 2012 02:01:42 GMT</pubDate><dc:creator>n.dineshbabu</dc:creator></item><item><title>Super XML noob needs help</title><link>http://www.sqlservercentral.com/Forums/Topic1292154-21-1.aspx</link><description>I've tried watching videos, reading reference books, reading blogs, and searching this forum, and I still don't understand how to do what I need to do.  Here is my XML document:[center][code="xml"]&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&amp;lt;MyRootElement&amp;gt;&amp;lt;text&amp;gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur egestas suscipit lectus, et hendrerit nulla malesuada in. Aliquam ultricies felis.&amp;lt;/text&amp;gt;&amp;lt;/MyRootElement&amp;gt;[/code][/center]I have over 31,000 &amp;lt;text&amp;gt; elements in the document inside the &amp;lt;MyRootElement&amp;gt;.I managed to bulk insert the XML file into SQL Server 2012 Express into a table called XmlImportTest.  If I do a SELECT * on the table I get two columns in my result set:A column with the filename of my document, and a second column of type xml that seems to contain my entire &amp;#100;ocument.  If I click on the second column I get an error that there was an unexpected end of file (which makes me suspicious that the entire file did not load) and I cannot open the file in the XML Editor in SSMS.That aside, what I need to do is insert the values inside the &amp;lt;text&amp;gt; tags into an existing column on another database table.  The examples I have seen so far don't match the simplicity of my document (just containing a root element with 31,000+ &amp;lt;text&amp;gt; elements).I need to understand how to do this, or if it's even possible to do inside SQL Server with my document in it's existing state.  I get the feeling that since the entire document is in one column in the XmlImportTest table I cannot parse it and separate out the individual &amp;lt;text&amp;gt; element values into multiple rows in the same column in another table.  I hope I'm wrong, but that is how it looks to me for now.I tried using the nodes() method in XQuery but could not get any results.  I'm stuck and don't know what I'm doing and so far haven't found anything that I can understand to help me.Thanks.</description><pubDate>Sun, 29 Apr 2012 08:41:07 GMT</pubDate><dc:creator>RHJ</dc:creator></item><item><title>WHY XML ?</title><link>http://www.sqlservercentral.com/Forums/Topic1287900-21-1.aspx</link><description>Hi friends,why we use almost xml scripts in most of the times in MSBI environment, can anybody reason for it?thanks NIha</description><pubDate>Sun, 22 Apr 2012 23:24:55 GMT</pubDate><dc:creator>niha.736</dc:creator></item><item><title>Shredding with XQuery to Parent, Child, Grandchild tables</title><link>http://www.sqlservercentral.com/Forums/Topic1278501-21-1.aspx</link><description>Hi,I'm sorry if this has been addressed already. I haven't been able to find it.Please consider the following XML.I need help to get to the next level.Each Purchase Order record can relate to 0..n Workorder records which can contain 0..n items.I've shown my 3rd table query but it generates duplicates...ThanksWalterDECLARE @xml XML = '&amp;lt;PurchaseOrder&amp;gt;  &amp;lt;PurchaseOrderNumber&amp;gt;1&amp;lt;/PurchaseOrderNumber&amp;gt;  &amp;lt;WorkOrder&amp;gt;    &amp;lt;WorkOrderNumber&amp;gt;11&amp;lt;/WorkOrderNumber&amp;gt;    &amp;lt;Item&amp;gt;		&amp;lt;ItemNumber&amp;gt;111&amp;lt;/ItemNumber&amp;gt;    &amp;lt;/Item&amp;gt;    &amp;lt;Item&amp;gt;		&amp;lt;ItemNumber&amp;gt;112&amp;lt;/ItemNumber&amp;gt;    &amp;lt;/Item&amp;gt;  &amp;lt;/WorkOrder&amp;gt;   &amp;lt;WorkOrder&amp;gt;    &amp;lt;WorkOrderNumber&amp;gt;12&amp;lt;/WorkOrderNumber&amp;gt;    &amp;lt;Item&amp;gt;		&amp;lt;ItemNumber&amp;gt;121&amp;lt;/ItemNumber&amp;gt;    &amp;lt;/Item&amp;gt;    &amp;lt;Item&amp;gt;		&amp;lt;ItemNumber&amp;gt;122&amp;lt;/ItemNumber&amp;gt;    &amp;lt;/Item&amp;gt;  &amp;lt;/WorkOrder&amp;gt;&amp;lt;/PurchaseOrder&amp;gt;'SELECT P.value('PurchaseOrderNumber[1]', 'VARCHAR(20)') PurchaseOrderNumberFROM @xml.nodes('/PurchaseOrder') AS PurchaseOrder(P)SELECT W.value('WorkOrderNumber[1]', 'VARCHAR(20)') WorkOrderNumber,	P.value('PurchaseOrderNumber[1]', 'VARCHAR(20)') PurchaseOrderNumber               FROM @xml.nodes('/PurchaseOrder/WorkOrder') AS WorkOrder(W)CROSS APPLY @xml.nodes('/PurchaseOrder') AS PurchaseOrder(P) -- this doesn't work: All the items have 2 records (1 for each workorder)SELECT I.value('ItemNumber[1]', 'VARCHAR(20)') ItemNumber,	W.value('WorkOrderNumber[1]', 'VARCHAR(20)') WorkOrderNumber,	P.value('PurchaseOrderNumber[1]', 'VARCHAR(20)') PurchaseOrderNumber               FROM @xml.nodes('/PurchaseOrder/WorkOrder/Item') AS Item(I)CROSS APPLY @xml.nodes('/PurchaseOrder/WorkOrder') AS WorkOrder(W)CROSS APPLY @xml.nodes('/PurchaseOrder') AS PurchaseOrder(P)</description><pubDate>Wed, 04 Apr 2012 19:01:53 GMT</pubDate><dc:creator>wdjong</dc:creator></item><item><title>Excluding Root Element in an XML Document</title><link>http://www.sqlservercentral.com/Forums/Topic1285724-21-1.aspx</link><description>Please refer to the attachment regarding an XML doc I am trying to shred.Questions:1.	This XML doc actually occurs in a column. Can I exclude the root element when querying the column?2.	How can I exclude specific duplicates of the Data element?</description><pubDate>Wed, 18 Apr 2012 09:22:43 GMT</pubDate><dc:creator>kennethigiri</dc:creator></item><item><title>SQLXMLBULKLOAD -- The transaction log for database [] is full</title><link>http://www.sqlservercentral.com/Forums/Topic1058647-21-1.aspx</link><description>I'm attempting to use Microsoft XML BulkLoad for SQL Server (SQLXMLBULKLOADLib) to load a six million row file to a [b]single [/b]table.The process aborts with The transaction log for database [] is full.This is running from a .NET application and I'm using the following parameters:[code="other"]Dim connectionString As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" &amp; AppMgr.DBuser &amp; _ ";Password=" &amp; AppMgr.DBPassword &amp; _ ";Initial Catalog=" &amp; AppMgr.DBName &amp; _ ";Data Source=" &amp; AppMgr.DBServerDim errorFile As String = AppMgr.clsConfig.FilePath &amp; "error.xml"xmlBulkLoad.ConnectionString = connectionStringxmlBulkLoad.ErrorLogFile = errorFilexmlBulkLoad.Transaction = FalsexmlBulkLoad.ForceTableLock =FalsexmlBulkLoad.CheckConstraints =FalsexmlBulkLoad.BulkLoad =TruexmlBulkLoad.Execute(AppMgr.AppDirectory &amp; "E4.xsd", gsDestinationPath &amp; InputConvertedTo)[/code]The process aborts and the following is logged in the error.xml file: [u]"The transaction log for database 'xxxxxx' is full"[/u]The code tests fine for smaller 100,000 row files but I get a few of these huge files.Shouldn't this be a mimimally logged operation?What am I doing wrong? Any help is greatly appreciated.SidPS. I'm using Microsoft XML BulkLoad for SQL Server 4.0 Type Libraryand the Database is in "Simple" recovery mode.</description><pubDate>Fri, 04 Feb 2011 05:30:01 GMT</pubDate><dc:creator>jcasement</dc:creator></item><item><title>Child Node</title><link>http://www.sqlservercentral.com/Forums/Topic517940-21-1.aspx</link><description>DECLARE @UserXML XMLSET @UserXML = '                                                                               'SELECT 	tblXML.Institution.query('Users/User/Email').value('.','varchar(50)') As Email,	tblXML.Institution.query('Users/User/BusinessRoleGuid').value('.','uniqueidentifier') As BusinessRoleGuidFROM @UserXML.nodes('//Institution') tblXML (Institution) How can I get the data is this formatInstitutionGUID	Email			BusinessRoleGUID0657F7ED-58CA-4A3D-8393-B9A3DD315319	A@Test.com 0657F7ED-58CA-4A3D-8393-B9A3DD315310657F7ED-58CA-4A3D-8393-B9A3DD315319	b@Test.com 1657F7ED-58CA-4A3D-8393-B9A3DD315319</description><pubDate>Mon, 16 Jun 2008 16:38:28 GMT</pubDate><dc:creator>Amit Lohia</dc:creator></item><item><title>Filtering results from SELECT on XML column</title><link>http://www.sqlservercentral.com/Forums/Topic1278749-21-1.aspx</link><description>Hi I have the following table:[code="sql"]CREATE TABLE XmlTable ([ImportData] [xml] NOT NULL) ON [Primary][/code]I have the following XML format:[code="xml"]&amp;lt;Parent&amp;gt;   &amp;lt;ID&amp;gt;1234&amp;lt;/ID&amp;gt;   &amp;lt;Child&amp;gt;      &amp;lt;State&amp;gt;1&amp;lt;/State&amp;gt;      &amp;lt;Value&amp;gt;X&amp;lt;/Value&amp;gt;   &amp;lt;/Child&amp;gt;   &amp;lt;Child&amp;gt;      &amp;lt;State&amp;gt;2&amp;lt;/State&amp;gt;      &amp;lt;Value&amp;gt;Y&amp;lt;/Value&amp;gt;   &amp;lt;/Child&amp;gt;&amp;lt;/Parent&amp;gt;[/code]and I want to select all the child values like this:[code="sql"]SELECT child.value('(parent::node()/ID/text)[1]', 'NVARCHAR(50)') AS [ID]      , child.value('(State/text)[1]', 'NVARCHAR(50)') AS [State]      , child.value('(Value/text)[1]', 'NVARCHAR(50)') AS [Value]   FROM [XmlTable] AS T CROSS APPLY [ImportData].nodes('/Parent/Child') AS ImportData(child)[/code]I need to restrict (like a WHERE clause) on the value of the State element of the Child element e.g. all States where it isn't 1:[code="other"]ID          State       Value1234        2           Y[/code]I have tried various methods for half a day now. Can anyone help? Please?PS Please excuse any typos as I am working in a Hyper-V VM with wireless network access so it has all been retyped by hand as I cannot access network from VM :-(</description><pubDate>Thu, 05 Apr 2012 06:47:49 GMT</pubDate><dc:creator>Gary Varga</dc:creator></item><item><title>Appendix B: Suppress namespace attributes in nested SELECT FOR XML</title><link>http://www.sqlservercentral.com/Forums/Topic1267029-21-1.aspx</link><description>This issue will be 5 years old two weeks from tomorrow so we can take out time.  But maybe a little poke might be appropriate.I do have to get this solved but I'm thinkin' maybe Pascal, C or our old company DIBOL?We generated XML with that and it looked just fine.The attachment started out as an appendix to my documentation for the project, hence 'Appendix B', but evolved somewhat.The attachment has test data, code, references and snide remarks.It might even be good as a final exam question.You have my permission.Thanks</description><pubDate>Wed, 14 Mar 2012 12:46:44 GMT</pubDate><dc:creator>Big Bay Boater</dc:creator></item><item><title>Insert special characters into table via XML</title><link>http://www.sqlservercentral.com/Forums/Topic1264203-21-1.aspx</link><description>I am using sql server 2000 and trying to insert bulk records into a table using XML format. Below is the sample XML format I'm using.&amp;lt;?xml version="1.0" encoding="iso-8859-1"?&amp;gt;&amp;lt;batch&amp;gt;&amp;lt;data&amp;gt;&amp;lt;cardid&amp;gt;010500350000&amp;lt;/cardid&amp;gt;&amp;lt;pinnumber&amp;gt;•G&#x1E;Z§-É±Ú&amp;lt;/pinnumber&amp;gt;&amp;lt;/data&amp;gt;&amp;lt;/batch&amp;gt;And the code to insert it to the table is as follows,DECLARE @BATCHUPLOAD_XML textDECLARE @idoc INTEXEC sp_xml_preparedocument @idoc OUTPUT, @BATCHUPLOAD_XMLINSERT INTO test_table(cardid,pinnumber) SELECT cardid,pinnumberFROM OPENXML (@idoc, '/batch/data')  WITH (cardid varchar(100) '@cardid', pinnumber varchar(100) '@pinnumber')This is working fine for normal characters. But if I use an encoded characters like •G&#x1E;Z§-É±Ú or N&#x1F;X”(ÍµÒzÉÓ I found that some characters (like • or ”) are replaced by question mark(?) in the database. This is causing lot of issues to me. Any help at the earliest will be greatly appreciated.Thanks,Rakesh.</description><pubDate>Fri, 09 Mar 2012 03:05:40 GMT</pubDate><dc:creator>rakesh.1263</dc:creator></item><item><title>Shredding XML using T-SQL</title><link>http://www.sqlservercentral.com/Forums/Topic1263462-21-1.aspx</link><description>Hi,I am trying to extract data from an XML file. eg&amp;lt;root&amp;gt;&amp;lt;album&amp;gt;&amp;lt;producttype&amp;gt;music&amp;lt;/producttype&amp;gt;&amp;lt;barcode&amp;gt;111111111&amp;lt;/barcode&amp;gt;&amp;lt;productname&amp;gt;This is a test album&amp;lt;/productname&amp;gt;&amp;lt;tracks&amp;gt;&amp;lt;track&amp;gt;&amp;lt;cdno&amp;gt;1&amp;lt;/cdno&amp;gt;&amp;lt;trackname&amp;gt;my first single&amp;lt;/trackname&amp;gt;&amp;lt;/track&amp;gt;&amp;lt;track&amp;gt;&amp;lt;cdno&amp;gt;2&amp;lt;/cdno&amp;gt;&amp;lt;trackname&amp;gt;My second track&amp;lt;/trackname&amp;gt;&amp;lt;/track&amp;gt;&amp;lt;/tracks&amp;gt;&amp;lt;notes&amp;gt;&amp;lt;note&amp;gt;&amp;lt;text&amp;gt;This album is home produced by myself and hopefully will be liked by many&amp;lt;/text&amp;gt;&amp;lt;/note&amp;gt;&amp;lt;/notes&amp;gt;&amp;lt;/album&amp;gt;Is there a way of extracting this in one go or dynamically as i have many XML files that has a samilar structure so my intention is too loop thru xml files with SSIS and process it one at a time based on the info i get perhaps from the XSD file eg.&amp;lt;?xml version="1.0"?&amp;gt;&amp;lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;  &amp;lt;xs:element name="root"&amp;gt;    &amp;lt;xs:complexType&amp;gt;      &amp;lt;xs:sequence&amp;gt;        &amp;lt;xs:element minOccurs="0" maxOccurs="unbounded" name="album"&amp;gt;          &amp;lt;xs:complexType&amp;gt;            &amp;lt;xs:sequence&amp;gt;              &amp;lt;xs:choice maxOccurs="unbounded"&amp;gt;                &amp;lt;xs:element minOccurs="0" name="producttype" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="barcode" type="xs:unsignedLong" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="barcodetype" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="origin" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="title" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="artist" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="altartist" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="composer" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="stock" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="coupling" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="source" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="label" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="media" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="mediatype" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="mediacount" type="xs:unsignedByte" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="releasedate" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="coding" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="supergenre" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="features" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="genre" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="pricedate" type="xs:date" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="price" type="xs:unsignedInt" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="rrp" type="xs:unsignedInt" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="distribprice" type="xs:unsignedInt" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="import" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="stocklevel" type="xs:unsignedShort" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="avaliable" type="xs:unsignedByte" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="AudioFormat" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="runtime" type="xs:unsignedShort" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="agelimit" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="tracks"&amp;gt;                  &amp;lt;xs:complexType mixed="true"&amp;gt;                    &amp;lt;xs:sequence minOccurs="0"&amp;gt;                      &amp;lt;xs:element minOccurs="0" maxOccurs="unbounded" name="track"&amp;gt;                        &amp;lt;xs:complexType&amp;gt;                          &amp;lt;xs:sequence&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="name" type="xs:string" /&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="cdno" type="xs:unsignedByte" /&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="trackno" type="xs:unsignedByte" /&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="artist" type="xs:string" /&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="asfclip" type="xs:string" /&amp;gt;                          &amp;lt;/xs:sequence&amp;gt;                        &amp;lt;/xs:complexType&amp;gt;                      &amp;lt;/xs:element&amp;gt;                    &amp;lt;/xs:sequence&amp;gt;                  &amp;lt;/xs:complexType&amp;gt;                &amp;lt;/xs:element&amp;gt;                &amp;lt;xs:element minOccurs="0" name="notes"&amp;gt;                  &amp;lt;xs:complexType mixed="true"&amp;gt;                    &amp;lt;xs:sequence minOccurs="0"&amp;gt;                      &amp;lt;xs:element minOccurs="0" name="note"&amp;gt;                        &amp;lt;xs:complexType mixed="true"&amp;gt;                          &amp;lt;xs:sequence minOccurs="0"&amp;gt;                            &amp;lt;xs:element minOccurs="0" name="text" type="xs:string" /&amp;gt;                          &amp;lt;/xs:sequence&amp;gt;                        &amp;lt;/xs:complexType&amp;gt;                      &amp;lt;/xs:element&amp;gt;                    &amp;lt;/xs:sequence&amp;gt;                  &amp;lt;/xs:complexType&amp;gt;                &amp;lt;/xs:element&amp;gt;                &amp;lt;xs:element minOccurs="0" name="pricecode" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="director" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="language" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="VideoFormat" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="platform" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="conductor" type="xs:string" /&amp;gt;                &amp;lt;xs:element minOccurs="0" name="deleted" type="xs:unsignedByte" /&amp;gt;              &amp;lt;/xs:choice&amp;gt;            &amp;lt;/xs:sequence&amp;gt;          &amp;lt;/xs:complexType&amp;gt;        &amp;lt;/xs:element&amp;gt;      &amp;lt;/xs:sequence&amp;gt;    &amp;lt;/xs:complexType&amp;gt;  &amp;lt;/xs:element&amp;gt;&amp;lt;/xs:schema&amp;gt;Is there also a way of dynamically changing the Output column in the XML Source component of SSIS. If this is possible the is would be simpler to let SSIS do all the work by obtaining an XML file, loop thru the Output columns and import. The move on to the next one.I am not a .net programmer so would appreciate if most of the suggestions could be SSIS or T-SQL.Much appreciated.Ismail</description><pubDate>Thu, 08 Mar 2012 01:24:56 GMT</pubDate><dc:creator>ismailmallum</dc:creator></item><item><title>Extract XML From SQL</title><link>http://www.sqlservercentral.com/Forums/Topic1261999-21-1.aspx</link><description>I have inherited a system which is a SQL Database which stores XML data in a Text Column.I have an exe which extracts the data into xml Files and then re-imports using SSIS into a relational format.I have schema files (xsd) but would like to ideally import the data directly into a relational format without the need to export (especially as I need to add more data and the exe is uneditable).I have no real xml experience, so the simpler solution the better.Any thoughts on the best way?Thanks.</description><pubDate>Tue, 06 Mar 2012 02:14:48 GMT</pubDate><dc:creator>Michaelro</dc:creator></item><item><title>Insert into table from xml</title><link>http://www.sqlservercentral.com/Forums/Topic1256554-21-1.aspx</link><description>Hi[code="sql"]CREATE table #Table1 (ID1 int,ID2 int,ID3 tinyint)DECLARE @x xmlDECLARE @ID1 intSET @ID1  = 1SET @x  = '&amp;lt;Products&amp;gt;&amp;lt;ProductType&amp;gt;	&amp;lt;ProductTypeID&amp;gt;101&amp;lt;/ProductTypeID&amp;gt;	&amp;lt;Product&amp;gt;		&amp;lt;ProductID&amp;gt;1&amp;lt;/ProductID&amp;gt; 		&amp;lt;ProductID&amp;gt;2&amp;lt;/ProductID&amp;gt; 	&amp;lt;/Product&amp;gt;&amp;lt;/ProductType&amp;gt;	&amp;lt;ProductType&amp;gt;	&amp;lt;ProductTypeID&amp;gt;102&amp;lt;/ProductTypeID&amp;gt;	&amp;lt;Product&amp;gt;		&amp;lt;ProductID&amp;gt;5&amp;lt;/ProductID&amp;gt; 		&amp;lt;ProductID&amp;gt;6&amp;lt;/ProductID&amp;gt; 	&amp;lt;/Product&amp;gt;&amp;lt;/ProductType&amp;gt;	&amp;lt;/Products&amp;gt;'INSERT INTO [dbo].[#Table1]				(					ID1, 					ID2,					ID3									)  				SELECT 					  @ID1					  ,V.y.value('(./ProductID)[1]','int') AS ID2					  ,V.y.value('(//ProductTypeID)[1]','tinyint') AS  ID3 					  --,V.y.value('.','int')  AS ProductID					  					  					  				FROM @x.nodes('/Products/ProductType/Product') AS V(y)				SELECT * FROM #Table1GO 				DROP TABLE 	#Table1		GO[/code] I want to insert the value from the xml into table ..pls help</description><pubDate>Thu, 23 Feb 2012 04:58:23 GMT</pubDate><dc:creator>dilipd006</dc:creator></item><item><title>XML conversion problem</title><link>http://www.sqlservercentral.com/Forums/Topic1253495-21-1.aspx</link><description>Hello All - I am newer creating XML and this is a For XML Path.  When I do a specific query outside of the xml creation I get the number I am looking for which is the column called SellAmount. So the math would basically be like this.350 * 0.6382SellAmount223.37 but when I run it in the xml it has a messed up conversion. Does anyone have anythoughts on this.[code="xml"]&amp;lt;CostingItem ID="2" Description="Port Charges" UnitQuantity="2" VendorCurrencyCode="GBP" CustomerPaysVendorDirectFlag="false" CustomerPaysVendorLocallyFlag="false" NetAmountChangeReasonCode="ZZZ" CalcMarginAsMarkupNotCommissionFlag="false" CostingType="Base Fare" PERuleAppliedFlag="true" PEProcessedFlag="true" PointsValue="0" PointsCashEquivalentamount="0.00"&amp;gt;  &amp;lt;Sell TotalAmount="2.233700000000000e+002" AmountsInVendorCurrencyFlag="false" /&amp;gt;  &amp;lt;Net TotalAmount="2.233700000000000e+002" /&amp;gt;&amp;lt;/CostingItem&amp;gt;[/code] [code="sql"]CASE WHEN SUM(cb.currencyrecnocruiseline) = 1 THEN CONVERT(MONEY,SUM(trans.portcharges)) * (SELECT convrate FROM content..currency_rates WHERE currencyrecno = 2 AND enddate = '2099-01-01 00:00:00.000')             ELSE ROUND(RTRIM(SUM(trans.portcharges)),2) END AS "CostingItem/Sell/@TotalAmount",[/code]</description><pubDate>Thu, 16 Feb 2012 15:15:23 GMT</pubDate><dc:creator>swilliams-1062888</dc:creator></item><item><title>Using OPENXML with complex XML structure</title><link>http://www.sqlservercentral.com/Forums/Topic1250624-21-1.aspx</link><description>Hey everyone,I searched but can't find any examples describing how to interrogate some specific XML. I have an XML structure that is (shall we say) less than optimal, but for the sake of argument, I can't change it, I have to deal with it as it is. Below is an example of what I'm trying to do===========================================================================DECLARE @hdoc int,@str nvarchar(max)set @str = '&amp;lt;root&amp;gt;	&amp;lt;item&amp;gt;		&amp;lt;var name="ITEMID"&amp;gt;			&amp;lt;number&amp;gt;3520.0&amp;lt;/number&amp;gt;		&amp;lt;/var&amp;gt;		&amp;lt;var name="QTY"&amp;gt;			&amp;lt;number&amp;gt;2.0&amp;lt;/number&amp;gt;		&amp;lt;/var&amp;gt;		&amp;lt;var name="ITEMTYPE"&amp;gt;			&amp;lt;string&amp;gt;thingy&amp;lt;/string&amp;gt;		&amp;lt;/var&amp;gt;	&amp;lt;/item&amp;gt;&amp;lt;/root&amp;gt;'	EXEC sp_xml_preparedocument @hdoc OUTPUT, @str	SELECT	*	FROM	OPENXML (@hdoc, '/root/item',8)	WITH	(		[type]	varchar(20)	'var[3]/string',		[id]	float		'var[1]/number',		[qty]	float		'var[2]/number'	)AS x	EXEC sp_xml_removedocument @hdoc===========================================================================I want a recordset with 1 record and 3 columns... Now, this works just fine... However, If the "VAR" columns in the source XML were to be re-ordered this would break.Is there a way to say "make the TYPE column = the STRING of the VAR record who's NAME = "ITEMTYPE"... ?Any ideas?</description><pubDate>Fri, 10 Feb 2012 16:56:18 GMT</pubDate><dc:creator>toddkingham</dc:creator></item><item><title>propblem in installing VS 2010</title><link>http://www.sqlservercentral.com/Forums/Topic1247049-21-1.aspx</link><description>when i install VS 2010i find this error in the attachplz help to complete my install it`s emergency</description><pubDate>Sun, 05 Feb 2012 17:24:03 GMT</pubDate><dc:creator>abeerbalah</dc:creator></item><item><title>insert value from xml to the table</title><link>http://www.sqlservercentral.com/Forums/Topic1247947-21-1.aspx</link><description>Hifollwing is the code i had use [code="sql"]DECLARE @GroupID int  = 1DECLARE @Agency xmlSET @Agency = '&amp;lt;Agency&amp;gt;					&amp;lt;AgencyID&amp;gt;1&amp;lt;/AgencyID&amp;gt; 					&amp;lt;AgencyID&amp;gt;2&amp;lt;/AgencyID&amp;gt; 					&amp;lt;AgencyID&amp;gt;3&amp;lt;/AgencyID&amp;gt;				&amp;lt;/Agency&amp;gt;'CREATE TABLE #temp (id int identity,AgencyID int,GroupID int )INSERT INTO #temp				(					 AgencyID					,GroupID 				)  				SELECT 					  V.y.value('(//AgencyID)[1]','int')  AS AgencyID					  ,@GroupID				FROM @Agency.nodes('/Agency/AgencyID') AS V(y)			SELECT * FROM #temp DROP TABLE #temp	[/code]this resul is coming while executing the above code, the agency id is not coming right instaed of coming 1,2,3 it is repeating 1id       AgencyID   GroupID1	1	12	1	13	1	1i want the following resultid       AgencyID   GroupID1	1	12	2	13	3	1</description><pubDate>Tue, 07 Feb 2012 03:42:00 GMT</pubDate><dc:creator>dilipd006</dc:creator></item><item><title>Extract field containing XML file and load results into a datatable</title><link>http://www.sqlservercentral.com/Forums/Topic1246578-21-1.aspx</link><description>Hi,I was wondering how I can accomplished the following:1. Data Field contains an entire XML File2. Extract the contents of that field and load to a new datatableThanks in advance</description><pubDate>Fri, 03 Feb 2012 08:59:47 GMT</pubDate><dc:creator>Joe Contreras-290946</dc:creator></item><item><title>Repeating Child Element Help - XML to SQL</title><link>http://www.sqlservercentral.com/Forums/Topic1240594-21-1.aspx</link><description>Hello all.New to XML and any help is appreciated.Code:[code="sql"]IF OBJECT_ID('tempdb..#TableExample') IS NOT NULLDROP TABLE #TableExampleGOCREATE TABLE #TableExample(XMLData xml)INSERT INTO #TableExampleVALUES('&amp;lt;?xml version="1.0" encoding="ISO-8859-1"?&amp;gt;&amp;lt;Directory&amp;gt;	&amp;lt;Groups GroupName = "Management"&amp;gt;		&amp;lt;EmpID&amp;gt;45612&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;84512&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;32247&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;91548&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;64656&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;32487&amp;lt;/EmpID&amp;gt;	&amp;lt;/Groups&amp;gt;	&amp;lt;Groups GroupName = "ITDEV"&amp;gt;		&amp;lt;EmpID&amp;gt;47312&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;88451&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;48165&amp;lt;/EmpID&amp;gt;		&amp;lt;EmpID&amp;gt;34567&amp;lt;/EmpID&amp;gt;	&amp;lt;/Groups&amp;gt;&amp;lt;/Directory&amp;gt;')SELECT   R.N.query('.').value('(/Groups/EmpID/.)[1]','int') AS CustomerIDFROM   #TableExample TECROSS APPLY  TE.Xmldata.nodes('/Directory/Groups') R(N)[/code]I'm able to pull the top EmpID from each Group, but I actually need to do 2 things.  Each EmpID(# can vary) and it's respective GroupName.I've searched hours for a solution, but no luck.Output to be something like this:Department    EmployeeID-------------------------Management   45612Management   84512Management   32247Management   91548Management   64656Management   32487ITDEV            47312ITDEV            88451ITDEV            48165ITDEV            34567</description><pubDate>Mon, 23 Jan 2012 20:34:16 GMT</pubDate><dc:creator>beefderky</dc:creator></item><item><title>Shredding XML using XQuery</title><link>http://www.sqlservercentral.com/Forums/Topic1239037-21-1.aspx</link><description>Hey all, I am having some issues with XML and XQuery in SQL. Here is basically what I wantI have some XML like this&amp;lt;a&amp;gt;  &amp;lt;b&amp;gt;one&amp;lt;/b&amp;gt;  &amp;lt;c&amp;gt;two&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;d&amp;gt;  &amp;lt;b&amp;gt;three&amp;lt;/b&amp;gt;  &amp;lt;c&amp;gt;four&amp;lt;/b&amp;gt;&amp;lt;/d&amp;gt;.....And I want to write a SQL statement using XQuery that will return the following(column name)    (column name)-----------------    ------------------one                       twothree                    fourAny thoughts?</description><pubDate>Thu, 19 Jan 2012 13:29:47 GMT</pubDate><dc:creator>SQL STEWIE</dc:creator></item><item><title>XML, XSDs and RecordReference tag</title><link>http://www.sqlservercentral.com/Forums/Topic1239295-21-1.aspx</link><description>Hi everyoneI have a question about XML and XSD.In my XML file there are repeating elements. I have normalised the XML into several tables, but now I want to use SSIS/Bulk XML Load to import the data to improve load speeds etc.The problem I have is to specify that the record reference should be used for each repeating "table" element in the XSD.For example, if this is my XML:[code]&amp;lt;Product&amp;gt;&amp;lt;RecordReference&amp;gt;0001&amp;lt;/RecordReference&amp;gt;&amp;lt;ProductForm&amp;gt;BB&amp;lt;/ProductForm&amp;gt;&amp;lt;Title&amp;gt;	&amp;lt;TitleType&amp;gt;01&amp;lt;/TitleType&amp;gt;	&amp;lt;TitleText&amp;gt;Normandy before 1066&amp;lt;/TitleText&amp;gt;&amp;lt;/Title&amp;gt;&amp;lt;Contributor&amp;gt;	&amp;lt;SequenceNumber&amp;gt;1&amp;lt;/SequenceNumber&amp;gt;	&amp;lt;PersonName&amp;gt;Professor David Bates&amp;lt;/PersonName&amp;gt;&amp;lt;/Contributor&amp;gt;&amp;lt;Contributor&amp;gt;	&amp;lt;SequenceNumber&amp;gt;2&amp;lt;/SequenceNumber&amp;gt;	&amp;lt;PersonName&amp;gt;Professor J de Wet&amp;lt;/PersonName&amp;gt;&amp;lt;/Contributor&amp;gt;&amp;lt;/Product&amp;gt;[/code]I have a table called Contributor, with the RecordReference, SequenceNumber and PersonName fields.So how would I change the XSD to "include" the RecordReference in the Contributor element?[code]        &amp;lt;xs:element minOccurs="0" maxOccurs="unbounded" name="Product"&amp;gt;          &amp;lt;xs:complexType&amp;gt;            &amp;lt;xs:sequence&amp;gt;              &amp;lt;xs:element minOccurs="0" name="RecordReference" type="xs:unsignedLong" /&amp;gt;              &amp;lt;xs:element minOccurs="0" name="ProductForm" type="xs:string" /&amp;gt;              &amp;lt;xs:element minOccurs="0" name="Contributor" Reference to RecordReference here&amp;gt;                &amp;lt;xs:complexType&amp;gt;                  &amp;lt;xs:sequence&amp;gt;                    &amp;lt;xs:element minOccurs="0" name="SequenceNumber" type="xs:unsignedByte" /&amp;gt;                    &amp;lt;xs:element minOccurs="0" name="PersonName" type="xs:string" /&amp;gt;                  &amp;lt;/xs:sequence&amp;gt;                &amp;lt;/xs:complexType&amp;gt;              &amp;lt;/xs:element&amp;gt;          &amp;lt;/xs:complexType&amp;gt;        &amp;lt;/xs:element&amp;gt;[/code]any ideas?Thanks</description><pubDate>Fri, 20 Jan 2012 04:24:07 GMT</pubDate><dc:creator>Jako de Wet</dc:creator></item><item><title>Multiple values to XML</title><link>http://www.sqlservercentral.com/Forums/Topic1238252-21-1.aspx</link><description>Hello all,  I'm very new to writing sql for xml output.  I'm struggling with how to write the syntax for multiple values.  I'm not very familiar with the terminology but I'll do my best to explain. I have a patient table that I need to join to several tables that have multiple values.SELECTP.PatientID AS "PatientInfo/PatientID",P.PatientName AS "PatientInfo/PatientName",P.UnitNumber AS "PatientInfo/UnitNumber",PVS.DateTime AS "PatientInfo/patientVitalSign/vitalSignDateTime",PVS.Vital AS "PatientInfo/patientVitalSign/vitalSign/vital",PVS.Value AS "PatientInfo/patientVitalSign/vitalSign/value"FROM Patient PLEFT JOIN PatientVitalSigns PVSON P.PatientID = PVS.PatientIDFOR XML PATH;The way it is written it will start the patient data over for each new row.  I need the patient to only print once then the vital signs repeat as needed like below:&amp;lt;- &amp;lt;patientVitalSign&amp;gt;  &amp;lt;vitalSignDateTime&amp;gt;2011-07-11T20:00:00&amp;lt;/vitalSignDateTime&amp;gt; - &amp;lt;vitalSign&amp;gt;  &amp;lt;vital&amp;gt;Temp&amp;lt;/vital&amp;gt;   &amp;lt;value&amp;gt;98.2&amp;lt;/value&amp;gt;   &amp;lt;/vitalSign&amp;gt;- &amp;lt;vitalSign&amp;gt;  &amp;lt;vital&amp;gt;Pulse&amp;lt;/vital&amp;gt;   &amp;lt;value&amp;gt;142&amp;lt;/value&amp;gt;   &amp;lt;/vitalSign&amp;gt;- &amp;lt;vitalSign&amp;gt;  &amp;lt;vital&amp;gt;Resp&amp;lt;/vital&amp;gt;   &amp;lt;value&amp;gt;66&amp;lt;/value&amp;gt;   &amp;lt;/vitalSign&amp;gt;  &amp;lt;/patientVitalSign&amp;gt;- &amp;lt;patientVitalSign&amp;gt;  &amp;lt;vitalSignDateTime&amp;gt;2011-06-11T16:00:00&amp;lt;/vitalSignDateTime&amp;gt; - &amp;lt;vitalSign&amp;gt;  &amp;lt;vital&amp;gt;Temp&amp;lt;/vital&amp;gt;   &amp;lt;value&amp;gt;98.5&amp;lt;/value&amp;gt;Thank you for the help!!!  Jamie</description><pubDate>Wed, 18 Jan 2012 13:33:41 GMT</pubDate><dc:creator>jamie Gerardo</dc:creator></item><item><title>creating XSL from code...</title><link>http://www.sqlservercentral.com/Forums/Topic1238497-21-1.aspx</link><description>Following the XML/XSL transformation using templates now I want to create a kind of "wizard" that works on the background to automatically create an XSL. Anyone with recommendations? Maybe someone has done something similar?For now I will start by saving the text a user enters on a text area on each key stroke. At same time the user can double click on a tree leaf and add a value to the text (name, email, full address, invoice number, etc). When this action adds the corresponding text I will add too the corresponding xsl sentence to the text created on background using the name of the clicked node and its parents. No need to add formatting, for now we do not have that option on the edit area.My goal is that at the end of edit the user can send the message but at same time save the message as a template if he wants. The template is the XSL that has been created dinamically on background.</description><pubDate>Thu, 19 Jan 2012 01:52:02 GMT</pubDate><dc:creator>yazalpizar_</dc:creator></item><item><title>XML-XSL transformation</title><link>http://www.sqlservercentral.com/Forums/Topic1233235-21-1.aspx</link><description>Found this article [url=http://www.sqlservercentral.com/articles/MDS/75932/]XML-XSL Transformations in SQL Server[/url] but I wonder if there is another way to accomplish that on SQl Server?</description><pubDate>Tue, 10 Jan 2012 07:47:26 GMT</pubDate><dc:creator>yazalpizar_</dc:creator></item><item><title>generate an XML using a template</title><link>http://www.sqlservercentral.com/Forums/Topic1234555-21-1.aspx</link><description>Hi everyone,I've used XML PATH and Elements to generate xml, so far so good. But now I'm thinking on a different approach and see if it is possible.I have several pre-created empty XML files, something like templates. The xml I want to create are exactly like those, and the complexity inside the XML is big, lot of child nodes, attributes, etc.Is there a way I can create an XML but "telling" the SQL Server to use those XML templates as a guide? Does this possibility exists? I've done some research and I can not find anything alike.Thanks!</description><pubDate>Thu, 12 Jan 2012 01:12:53 GMT</pubDate><dc:creator>yazalpizar_</dc:creator></item><item><title>Inserting XML field into new Table</title><link>http://www.sqlservercentral.com/Forums/Topic1235884-21-1.aspx</link><description>Dear All, I am facing issue while extracting data from one field. I want to split data into new table with based on XML tags. For example in attached statement I want to separate Kpi, Desc, Min, Max, Rate and Comments fields into new table. Thanks in advance.</description><pubDate>Fri, 13 Jan 2012 12:05:00 GMT</pubDate><dc:creator>waheed71</dc:creator></item><item><title>inserting the xml elements into existing table</title><link>http://www.sqlservercentral.com/Forums/Topic1227696-21-1.aspx</link><description>Hi All,Iam having the xml with the data as shown below, declare @x xmlset @x = '&amp;lt;SinterklaasWishlists&amp;gt;   &amp;lt;child&amp;gt;      &amp;lt;name&amp;gt;Tim&amp;lt;/name&amp;gt;      &amp;lt;wishlist&amp;gt;         &amp;lt;article&amp;gt;            &amp;lt;artno&amp;gt;21491269&amp;lt;/artno&amp;gt;            &amp;lt;description&amp;gt;Crane&amp;lt;/description&amp;gt;            &amp;lt;price&amp;gt;12.50&amp;lt;/price&amp;gt;         &amp;lt;/article&amp;gt;         &amp;lt;article&amp;gt;            &amp;lt;artno&amp;gt;21499517&amp;lt;/artno&amp;gt;            &amp;lt;description&amp;gt;Keyboard&amp;lt;/description&amp;gt;            &amp;lt;price&amp;gt;10&amp;lt;/price&amp;gt;         &amp;lt;/article&amp;gt;         &amp;lt;article&amp;gt;            &amp;lt;artno&amp;gt;21521591&amp;lt;/artno&amp;gt;            &amp;lt;description&amp;gt;Crime Investigation Game&amp;lt;/description&amp;gt;            &amp;lt;price&amp;gt;9.95&amp;lt;/price&amp;gt;         &amp;lt;/article&amp;gt;      &amp;lt;/wishlist&amp;gt;   &amp;lt;/child&amp;gt;      &amp;lt;child&amp;gt;      &amp;lt;name&amp;gt;Tim2&amp;lt;/name&amp;gt;      &amp;lt;wishlist&amp;gt;         &amp;lt;article&amp;gt;            &amp;lt;artno&amp;gt;3145678&amp;lt;/artno&amp;gt;            &amp;lt;description&amp;gt;Mouse&amp;lt;/description&amp;gt;            &amp;lt;price&amp;gt;12.50&amp;lt;/price&amp;gt;         &amp;lt;/article&amp;gt;      &amp;lt;/wishlist&amp;gt;   &amp;lt;/child&amp;gt;&amp;lt;/SinterklaasWishlists&amp;gt;'I want to extract the elements of xml using sql query and insert the data into the table as shown below:CHILDNAME       ARTICLE_NUMBER       DESCRIPTION                         PRICE--------------- -------------------- ----------------------------------- -----------Tim1            21491269             Crane                               12.50Tim1            21499517             Keyboard                            10Tim1             21521591            Crime Investigation Game            9.95Tim2            3145678              Mouse                               12.50Kindly help me on the same</description><pubDate>Thu, 29 Dec 2011 02:55:44 GMT</pubDate><dc:creator>rams.prsk</dc:creator></item><item><title>extract data out of XML with two namespaces</title><link>http://www.sqlservercentral.com/Forums/Topic1219855-21-1.aspx</link><description>HiI'm trying to extract data out of an XML, and by and large am unable to get most of the data. It appears that the XML has two namespaces, and I only seem to be able to get the data out of one of them. I've new to XML and have trialled and errored a few things, but for the life of me cannot get the value of one of the elements.This is the XML:&amp;lt;s:ISMessage xmlns="http://informationsystems/schema/messages" xmlns:s="http://informationsystems/schema/messages"&amp;gt;  &amp;lt;s:Source&amp;gt;AuthoritativePublisher&amp;lt;/s:Source&amp;gt;  &amp;lt;s:DateAndTime&amp;gt;2011-11-16T08:28:39.247Z&amp;lt;/s:DateAndTime&amp;gt;  &amp;lt;s:ClassID&amp;gt;11005&amp;lt;/s:ClassID&amp;gt;  &amp;lt;s:Version&amp;gt;1&amp;lt;/s:Version&amp;gt;  &amp;lt;s:ClassDescription&amp;gt;Dumpstation 1 Unloading Task Commenced&amp;lt;/s:ClassDescription&amp;gt;  &amp;lt;s:Unloading&amp;gt;    &amp;lt;s:UnloadingTaskCommenced&amp;gt;      &amp;lt;TrainCycleID&amp;gt;43631&amp;lt;/TrainCycleID&amp;gt;      &amp;lt;Job&amp;gt;134178&amp;lt;/Job&amp;gt;      &amp;lt;s:UnloadingEvent&amp;gt;        &amp;lt;s:Events xmlns:s="http://controlsystems/schema/Events"&amp;gt;          &amp;lt;s:LogixEvent xmlns:s="http://controlsystems/schema/Events"&amp;gt;            &amp;lt;s:Source&amp;gt;PLC_ASU&amp;lt;/s:Source&amp;gt;            &amp;lt;s:DateAndTime&amp;gt;2011-11-16T08:28:39.246Z&amp;lt;/s:DateAndTime&amp;gt;            &amp;lt;s:ClassID&amp;gt;11005&amp;lt;/s:ClassID&amp;gt;            &amp;lt;s:Version&amp;gt;1&amp;lt;/s:Version&amp;gt;            &amp;lt;s:UnloadingEvent&amp;gt;              &amp;lt;s:UnloadingOperatorAction&amp;gt;                &amp;lt;s:StartTrain&amp;gt;                  &amp;lt;s:DumpStation&amp;gt;1&amp;lt;/s:DumpStation&amp;gt;                  &amp;lt;s:Destination&amp;gt;1011&amp;lt;/s:Destination&amp;gt;                  &amp;lt;s:SelectionID&amp;gt;15330&amp;lt;/s:SelectionID&amp;gt;                  &amp;lt;s:TaskID&amp;gt;205834&amp;lt;/s:TaskID&amp;gt;                  &amp;lt;s:WagonsProcessed&amp;gt;0&amp;lt;/s:WagonsProcessed&amp;gt;                  &amp;lt;s:TonnesProcessed&amp;gt;46&amp;lt;/s:TonnesProcessed&amp;gt;                &amp;lt;/s:StartTrain&amp;gt;              &amp;lt;/s:UnloadingOperatorAction&amp;gt;            &amp;lt;/s:UnloadingEvent&amp;gt;          &amp;lt;/s:LogixEvent&amp;gt;        &amp;lt;/s:Events&amp;gt;      &amp;lt;/s:UnloadingEvent&amp;gt;    &amp;lt;/s:UnloadingTaskCommenced&amp;gt;  &amp;lt;/s:Unloading&amp;gt;&amp;lt;/s:ISMessage&amp;gt;I can get the TrainCycleID and JobID details fine, but I also need to get the DumpStation, Destination, SelectionID, etc, and it seems the "s:" in the elements is confusing me. Anyone able to help?This is the query that I'm using. What am I missing ?WITH XMLNAMESPACES(            'http://informationsystems/schema/messages' as m,            'http://controlsystems/schema/Events' as s,            default 'http://informationsystems/schema/messages'      )      INSERT INTO @JourneyDetails( TrainCycleID , JobID, EventDateAndTimeZulu, Dumpstation, Destination)      SELECT             x.value('(TrainCycleID)[1]','int') AS TrainCycleID,            x.value('(Job)[1]','int') AS JobID,            x.value('(s:Events/s:LogixEvent/s:DateAndTime)[1]','varchar(max)') AS EventDateAndTimeZulu,            x.value('(s:Events/s:LogixEvent/s:UnloadingEvent/s:UnloadingOperatorAction/s:StartTrain/s:DumpStation)[1]','varchar(max)') AS Dumpstation,            x.value('(s:Events/s:LogixEvent/s:UnloadingEvent/s:UnloadingOperatorAction/s:StartTrain/s:Destination)[1]','varchar(max)') AS Destination,                  FROM @xml.nodes('//UnloadingTaskCommenced') v(x)</description><pubDate>Sat, 10 Dec 2011 14:27:51 GMT</pubDate><dc:creator>plutekplutek</dc:creator></item><item><title>image to xml and xmlns="urn:" issue</title><link>http://www.sqlservercentral.com/Forums/Topic1215478-21-1.aspx</link><description>I have an image data type I would like to select into my XML &amp;#100;ocument.  When I select using query analyzer there is data there and formatted just as I would expect.  However, when I put it into the FOR XML Path selection it comes up blank and the related element is not there at all.  Can anyone tell me how to correct this?  It is likely I need a slightly different FOR XML command but I can't figure out what I am missing![code="sql"]select 	opt.AnswerText as "answerOption/text", 	opt.AnswerAbbr as "answerOption/abbr", 	opt.AnswerValue as "answerOption/value",	opt.Ordinal as "answerOption/ordinal", 	opt.RelatedImage as "answerOption/image/imgByte", 	it.ColumnValue as "answerOption/image/imgType",	a.LongName as "attribute/longName", 	a.ShortName as "attribute/shortName",	a.Information as "attribute/information"from rcs.tblAttributeReview_Link ar	inner join rcs.tblAttribute a on ar.AttributeUID = a.AttributeUID 	left join rcs.tblAnswerOption opt on a.AttributeUID = opt.AttributeUID	left join rcs.tblLookup it on opt.ImageType = it.LookupID FOR XML Path('reviewAttribute')[/code]which produces:[code="xml"]&amp;lt;reviewAttribute&amp;gt;  &amp;lt;id&amp;gt;4&amp;lt;/id&amp;gt;  &amp;lt;answerOption&amp;gt;    &amp;lt;id&amp;gt;8&amp;lt;/id&amp;gt;    &amp;lt;text&amp;gt;I need an answer&amp;lt;/text&amp;gt;    &amp;lt;value&amp;gt;0&amp;lt;/value&amp;gt;    &amp;lt;ordinal&amp;gt;0&amp;lt;/ordinal&amp;gt;    &amp;lt;enabled&amp;gt;0&amp;lt;/enabled&amp;gt;    &amp;lt;image&amp;gt;      &amp;lt;imgByte&amp;gt;&amp;lt;/imgByte&amp;gt;    &amp;lt;/image&amp;gt;  &amp;lt;/answerOption&amp;gt;  &amp;lt;attribute&amp;gt;    &amp;lt;id&amp;gt;2EDD5095-550E-430E-B55C-1055D29364BB&amp;lt;/id&amp;gt;    &amp;lt;longName&amp;gt;Attribute for Review&amp;lt;/longName&amp;gt;    &amp;lt;shortName&amp;gt;Review&amp;lt;/shortName&amp;gt;    &amp;lt;answerType&amp;gt;      &amp;lt;id&amp;gt;1&amp;lt;/id&amp;gt;      &amp;lt;columnValue&amp;gt;Free Text&amp;lt;/columnValue&amp;gt;    &amp;lt;/answerType&amp;gt;    &amp;lt;class&amp;gt;      &amp;lt;id&amp;gt;14&amp;lt;/id&amp;gt;      &amp;lt;columnValue&amp;gt;Response&amp;lt;/columnValue&amp;gt;    &amp;lt;/class&amp;gt;    &amp;lt;state&amp;gt;      &amp;lt;id&amp;gt;17&amp;lt;/id&amp;gt;      &amp;lt;columnValue&amp;gt;Edit&amp;lt;/columnValue&amp;gt;    &amp;lt;/state&amp;gt;    &amp;lt;enabled&amp;gt;1&amp;lt;/enabled&amp;gt;    &amp;lt;information&amp;gt;Some information that is interesting&amp;lt;/information&amp;gt;  &amp;lt;/attribute&amp;gt;&amp;lt;/reviewAttribute&amp;gt;[/code]It would be perfect if only the imgByte data actually showed up!  And there should be an imgType as well that exists when I select the data as data but is not showing up in the XML :(In addition to the issue above I want to have the entire thing start with [code="xml"]&amp;lt;reviewAttribute xmlns="urn:reviewset-1.0"&amp;gt;[/code]I have found ways to state the namespace but the formatting is never right.  If I try to add xmlns as an attribute to reviewAttribute SQL Server kicks an error that xmlns is not allowed as an attribute.  If anyone knows how to get exactly this format as the namespace declaration I would really appreciate the pointer!Thank you!</description><pubDate>Fri, 02 Dec 2011 09:20:18 GMT</pubDate><dc:creator>evaleah</dc:creator></item><item><title>Update XML attribute value using another XML attribute value</title><link>http://www.sqlservercentral.com/Forums/Topic1228771-21-1.aspx</link><description>Hello,I am using SQL Server 2008 R2. I have a requirement where I need to update one XML attribute value using another XML's same attribute's value.XML structure is like:[code="xml"]&amp;lt;Data&amp;gt;  &amp;lt;Items StatusId="10"&amp;gt;    &amp;lt;Item Id="3FF6AD1F-D6F0-43E4-8294-59D678DF478A" Name="HD 1" &amp;gt;      &amp;lt;ExtraColumns&amp;gt;        &amp;lt;Column RecordType="Sub" IsRecordExist="1" /&amp;gt;      &amp;lt;/ExtraColumns&amp;gt;    &amp;lt;/Item&amp;gt;    &amp;lt;Item Id="0F88289C-CCD4-47AB-AFC7-54A7F83A1019" Name="HD 2" &amp;gt;      &amp;lt;ExtraColumns&amp;gt;        &amp;lt;Column RecordType="Sub" IsRecordExist="1" /&amp;gt;      &amp;lt;/ExtraColumns&amp;gt;    &amp;lt;/Item&amp;gt;  &amp;lt;/Items&amp;gt;&amp;lt;/Data&amp;gt;[/code]I would like to change the "IsRecordExist" attribute value using another XML (which is generated by other process) - same structure. We can use "Id" column as Primary Key. Is there any way to do the same?</description><pubDate>Sun, 01 Jan 2012 23:00:46 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>manage mailing with XML templates</title><link>http://www.sqlservercentral.com/Forums/Topic1226853-21-1.aspx</link><description>Hello everyone, I'm a newbie and didn't knew where exactly to post this thread. I finally decided to post on XML forum as I believe it is related with it. Here is my question(s):I wanted to create a procedure that will receive a string and ouput another string, more or less like this:Input parameter: "Dear {client_id} your order {order_Id} with the enclosed {products_Id} has been shipped"Result: "Dear 'Yaroslav' your order 'Books on SQL Server' with the enclosed 'XML on Sql, SQL Tuning, SQL administration' has been shipped."I began the analysis and thought on 2 tables, one with the tokens and another one with templates of the emails or messages.Tables would be:[code="sql"]CREATE TABLE [dbo].[Token](	[TokenPk] [int] NOT NULL,	[Name] [nvarchar](50) NOT NULL, --this is the string to be used on the email: {client_id} for example	[Value] [nvarchar](50) NOT NULL, --this value will be the one used, but on my case, is a table.column reference: for {client_id} the value could be {clients.client_name}	[Description] [nvarchar](max) NULL, --generic description of the token CONSTRAINT [PK_Token] PRIMARY KEY CLUSTERED (	[TokenPk] ASC) ON [PRIMARY]CREATE TABLE [Clients].[DefaultMessage](	[DefaultAnswerPk] [int] IDENTITY(1,1) NOT NULL,	[Text] [nvarchar](max) NULL, --text of the message	[PriorityOrder] [int] NOT NULL, --there could be several messages available for same question, so we need a priority order	[DefaultMessageCategoryFk] [int] NOT NULL, --points to another table where we have several message categories CONSTRAINT [PK_DefaultAnswer_1] PRIMARY KEY CLUSTERED ([DefaultAnswerPk] ASC) ON [PRIMARY][/code]After giving second thoughts I believed XML/XSD/XSL could be handy here. The templates instead of plain text could be XML templates. Also I could have XSL files attached so we could create different formats for same email. And finally use XSD to validate the data. Even could use XSLT to transform the data and output pdf, html, doc, etc. Then I began to read anything related with XML on SQL Server as I want to process as much as I can using TSQL sentences. I've read all the XML workshop series by Jacob Sebastian and done several testings, more still to do.My questions are: - Is this "achiveable" on TSQL?- Has someone done something alike? Does not matter if it was using plain text, maybe it can help bringing some light to the matter- Wich should be my first steps towards creating a first small working procedure/function using XML to solve this?More questions will arise for sure, but now I'm somewhat lost on where to continue...</description><pubDate>Tue, 27 Dec 2011 05:28:13 GMT</pubDate><dc:creator>yazalpizar_</dc:creator></item><item><title>How to have an element and an attribute value in a tag</title><link>http://www.sqlservercentral.com/Forums/Topic1222082-21-1.aspx</link><description>I need an XML element that has an attribute and an element value. The result required is such:[i] &amp;lt;Party&amp;gt;    &amp;lt;CustomerID Role="SENDER"&amp;gt;1122334455&amp;lt;/CustomerID&amp;gt;    &amp;lt;Name&amp;gt;SomeOne&amp;lt;/Name&amp;gt;    &amp;lt;Address1&amp;gt;SomeWhere&amp;lt;/ADDRESS&amp;gt;    &amp;lt;City&amp;gt;SomeCity&amp;lt;/City&amp;gt; &amp;lt;/Party&amp;gt;  [/i] This is a subquery in part of a larger SQL XML query, the data is static so no table is referenced. The DB is SQL Server 2005.The query I am using is:([b]      SELECT      'SENDER'			'CustomerID/@Role',      '1122334455'			'CustomerID',          'SomeOne'			'Name',      'SomeWhere'			'Address1',      'SomeCity'			'City')     FOR XML path ('Party') [/b]But the result is:[i]&amp;lt;Party&amp;gt;    &amp;lt;CustomerID Role="SENDER"&amp;gt;    &amp;lt;/CustomerID&amp;gt;    &amp;lt;Name&amp;gt;SomeOne&amp;lt;/Name&amp;gt;    &amp;lt;Address1&amp;gt;SomeWhere&amp;lt;/Address1&amp;gt;    &amp;lt;City&amp;gt;SomeCity&amp;lt;/City&amp;gt;&amp;lt;/Party&amp;gt;[/i]Any ideas on what is missing or wrong with my query?</description><pubDate>Wed, 14 Dec 2011 15:04:36 GMT</pubDate><dc:creator>Brent Seeney-273128</dc:creator></item><item><title>Dynamic XPath in SQL query</title><link>http://www.sqlservercentral.com/Forums/Topic1163138-21-1.aspx</link><description>Hello,I have created a stored procedure which contains lines like below:	if @int = '0' 	begin		select @alert = (select replace(@alert,'{' + CAST(@int AS CHAR(1)) + '}',@N1.value('AlertParameters[1]/AlertParameter1[1]','varchar(max)')))	endand	if @int = '1' 	begin		select @alert = (select replace(@alert,'{' + CAST(@int AS CHAR(1)) + '}',@N1.value('AlertParameters[1]/AlertParameter2[1]','varchar(max)')))	endIt works but it's not really nice coding. I would like the 'AlertParameters[1]/AlertParameter[b]1[/b][1]' part to be dynamic so that I don't have to use an 'if begin ... end'  statement for all possible values of @int.How can I achive this?Best regards,Coen van Dijk</description><pubDate>Mon, 22 Aug 2011 01:56:12 GMT</pubDate><dc:creator>coen.van.dijk</dc:creator></item><item><title>all OutputList nodes from different parent nodes?</title><link>http://www.sqlservercentral.com/Forums/Topic1213116-21-1.aspx</link><description>In another thread, the question came up to find all dependancies of an executed SQL statement.Looking over some sample execution plans, I found it's not something that is simple, although all the data is in the execution plan.i can see that a sqlplan file will have multiple &amp;lt;RelOp&amp;gt;&amp;lt;OutputList&amp;gt;&amp;lt;ColumnReference&amp;gt; tags, all at different levels within the plan.I know how to use xquery to drill down to a specific tag, all the way from the top, like my script below,but my problem is there are multiple &amp;lt;RelOp&amp;gt;&amp;lt;OutpoutList&amp;gt;&amp;lt;ColumnReference&amp;gt; nodes, some under nested loops, others under other tags, all depending on the plan itself.how can i select &amp;lt;RelOp&amp;gt;&amp;lt;OutpoutList&amp;gt;&amp;lt;ColumnReference&amp;gt; nomatter what node/level in the xml it sits under?[code]WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS sp)SELECT p.query_plan,       DatabaseName = p.query_plan.value(N'(sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference/@Database)[1]', 'NVARCHAR(256)'),       TableName    = p.query_plan.value(N'(sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference/@Table)[1]', 'NVARCHAR(256)'),       SchemaName   = p.query_plan.value(N'(/sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference/@Schema)[1]', 'NVARCHAR(256)'),       ColumnName   = p.query_plan.value(N'(/sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference/@Column)[1]', 'NVARCHAR(256)'),       Alias        = p.query_plan.value(N'(/sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference/@Alias)[1]', 'NVARCHAR(256)')FROM   sys.dm_exec_query_stats s       CROSS APPLY sys.DM_EXEC_QUERY_PLAN(s.plan_handle) AS p      WHERE  p.query_plan.exist(N'/sp:ShowPlanXML/sp:BatchSequence/sp:Batch/sp:Statements/sp:StmtSimple/sp:QueryPlan/sp:RelOp/sp:OutputList/sp:ColumnReference') = 1 [/code]</description><pubDate>Tue, 29 Nov 2011 05:38:14 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>FOR XML child nodes depend on column value</title><link>http://www.sqlservercentral.com/Forums/Topic1211546-21-1.aspx</link><description>I have to do a lot of work on an SQL database that has some issues carried forward from an old legacy database,  it still uses line typing within the same table.I am trying to extract data as XML from these tables.Briefly, the OrderDetails table can contain either stock lines or comment lines.The desired result is:&amp;lt;SalesOrders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&amp;gt;  &amp;lt;Orders&amp;gt;    &amp;lt;OrderHeader&amp;gt;      &amp;lt;XOrder&amp;gt;WKMH10000 &amp;lt;/XOrder&amp;gt;      &amp;lt;CustomerPoNumber&amp;gt;1234&amp;lt;/CustomerPoNumber&amp;gt;      &amp;lt;Customer&amp;gt;BOL1000&amp;lt;/Customer&amp;gt;      &amp;lt;OrderDate&amp;gt;2011-10-10&amp;lt;/OrderDate&amp;gt;      &amp;lt;RequestedShipDate&amp;gt;2011-10-15&amp;lt;/RequestedShipDate&amp;gt;    &amp;lt;/OrderHeader&amp;gt;    &amp;lt;OrderDetails&amp;gt;      &amp;lt;StockLine&amp;gt;        &amp;lt;CustomerPoLine&amp;gt;1&amp;lt;/CustomerPoLine&amp;gt;        &amp;lt;LineActionType&amp;gt;A&amp;lt;/LineActionType&amp;gt;        &amp;lt;StockCode&amp;gt;WS8x30&amp;lt;/StockCode&amp;gt;        &amp;lt;OrderQty&amp;gt;1200.000&amp;lt;/OrderQty&amp;gt;        &amp;lt;Price&amp;gt;5.23000&amp;lt;/Price&amp;gt;      &amp;lt;/StockLine&amp;gt;      &amp;lt;CommentLine&amp;gt;        &amp;lt;CustomerPoLine&amp;gt;2&amp;lt;/CustomerPoLine&amp;gt;        &amp;lt;LineActionType&amp;gt;A&amp;lt;/LineActionType&amp;gt;        &amp;lt;Comment&amp;gt;This is a comment line&amp;lt;/Comment&amp;gt;        &amp;lt;AttachedLineNumber&amp;gt;1&amp;lt;/AttachedLineNumber&amp;gt;        &amp;lt;CommentType&amp;gt;A&amp;lt;/CommentType&amp;gt;      &amp;lt;/CommentLine&amp;gt;      &amp;lt;StockLine&amp;gt;        &amp;lt;CustomerPoLine&amp;gt;3&amp;lt;/CustomerPoLine&amp;gt;        &amp;lt;LineActionType&amp;gt;A&amp;lt;/LineActionType&amp;gt;        &amp;lt;StockCode&amp;gt;WS8x40&amp;lt;/StockCode&amp;gt;        &amp;lt;OrderQty&amp;gt;800.000&amp;lt;/OrderQty&amp;gt;        &amp;lt;Price&amp;gt;5.50000&amp;lt;/Price&amp;gt;      &amp;lt;/StockLine&amp;gt;          &amp;lt;/OrderDetails&amp;gt;  &amp;lt;/Orders&amp;gt; &amp;lt;/SalesOrders&amp;gt;I get this without the CustomerOrderLine2  (The comment line) by using this:select XOrder as [OrderHeader/XOrder],[CustomerPoNumber] as [OrderHeader/CustomerPoNumber],       Customer as [OrderHeader/Customer],       CONVERT(VARCHAR(10),OrderDate,120) as [OrderHeader/OrderDate],       CONVERT(VARCHAR(10),RequestedShipDate,120) as [OrderHeader/RequestedShipDate],	(Select			(select CustomerPoLine as [StockLine/CustomerPoLine],				'A' as [StockLine/LineActionType],                StockCode as [StockLine/StockCode],                OrderQty as [StockLine/OrderQty],                Price as [StockLine/Price]         		from OrderDetails 		where OrderDetails.XOrder = OrderHeaders.XOrder		AND LineType = 1		for xml path(''),type)	) as OrderDetailsfrom OrderHeaders for xml path('Orders'),elements XSINIL,root('SalesOrders')If I vary it slightly I get the CommentLine.  Like this:select XOrder as [OrderHeader/XOrder],[CustomerPoNumber] as [OrderHeader/CustomerPoNumber],       Customer as [OrderHeader/Customer],       CONVERT(VARCHAR(10),OrderDate,120) as [OrderHeader/OrderDate],       CONVERT(VARCHAR(10),RequestedShipDate,120) as [OrderHeader/RequestedShipDate],	(Select			(select CustomerPoLine as [CommentLine/CustomerPoLine],				'A' as [CommentLine/LineActionType],                Comment as [CommentLine/Comment],                AttachedLineNumber as [CommentLine/AttachedLineNumber],                CommentType as [CommentLine/CommentType]         		from OrderDetails 		where OrderDetails.XOrder = OrderHeaders.XOrder		AND LineType = 6		for xml path(''),type)	) as OrderDetailsfrom OrderHeaders for xml path('Orders'),elements XSINIL,root('SalesOrders')I have tried various ways of using CASE  or sub-queries but with no success.Does anybody out there have a solution for me?Thanks,  Ken</description><pubDate>Thu, 24 Nov 2011 04:13:35 GMT</pubDate><dc:creator>ken-1133369</dc:creator></item><item><title>for xml path query, nested nodes, do not include html translation</title><link>http://www.sqlservercentral.com/Forums/Topic1211217-21-1.aspx</link><description>I have the following query:[code="sql"]select	r.ReviewUID as "id",	r.RTitle as "title",	r.RDescription as "description",	r.CreatedDateUTC as "createdDate",	r.ImplementationDate as "implementationDate",	r.EffectiveDateUTC as "effectiveDate",	r.StateID as "state/id",	st.ColumnInt as "state/columnInt",	st.ColumnValue as "state/columnValue",	(select n.AttachType as "attachType/id", at.ColumnInt as "attachType/columnInt", at.ColumnValue as "attachType/columnValue",		n.NoteText as "text" from rcs.tblNotes n left join rcs.tblLookup at on n.AttachType = at.LookupID		where n.EntityUID = r.ReviewUID FOR XML Path('note')) as "notes"from rcs.tblReview rleft join rcs.tblLookup st on r.StateID = st.LookupIDwhere r.ReviewUID = '4412567C-7EFD-41E1-BAC2-747790C99018'FOR XML Path('review')[/code]which returns almost exactly what I need:&amp;lt;review&amp;gt;[code="xml"]  &amp;lt;id&amp;gt;4412567C-7EFD-41E1-BAC2-747790C99018&amp;lt;/id&amp;gt;  &amp;lt;title&amp;gt;FancyNewName&amp;lt;/title&amp;gt;  &amp;lt;description&amp;gt;A lot to say about this test review&amp;lt;/description&amp;gt;  &amp;lt;createdDate&amp;gt;2011-11-23T12:06:17&amp;lt;/createdDate&amp;gt;  &amp;lt;implementationDate&amp;gt;2011-11-27T12:06:17&amp;lt;/implementationDate&amp;gt;  &amp;lt;effectiveDate&amp;gt;2011-11-27T12:06:17&amp;lt;/effectiveDate&amp;gt;  &amp;lt;state&amp;gt;    &amp;lt;id&amp;gt;17&amp;lt;/id&amp;gt;    &amp;lt;columnInt&amp;gt;1&amp;lt;/columnInt&amp;gt;    &amp;lt;columnValue&amp;gt;Edit&amp;lt;/columnValue&amp;gt;  &amp;lt;/state&amp;gt;  &amp;lt;notes&amp;gt;&amp; lt;note&amp;gt;&amp; lt;text&amp; gt;An addition note to add to the review&amp; lt;/text&amp; gt;&amp; lt;/note&amp; gt;&amp;lt;/notes&amp;gt;&amp;lt;/review&amp;gt;[/code]Only I do not want the "&amp;lt;" and "&amp;gt;" characters to be escaped for html.  I want them raw.  How do I alter what I have above to get exactly this only really as just xml?PLEASE NOTE:  The spaces in the html escape characters were added so this would show up correctly in this post.  Otherwise, the parsers were showing what was being escaped.  The spaces do not actually exist in my output.Thanks!</description><pubDate>Wed, 23 Nov 2011 10:46:17 GMT</pubDate><dc:creator>evaleah</dc:creator></item><item><title>Merging 2 XML Nodes into 1 SQL Table using SSIS</title><link>http://www.sqlservercentral.com/Forums/Topic1209742-21-1.aspx</link><description>Hello,I'll try and keep this simple.I have an XML file, 2 nodes of which I'm concerning about. A 'Supplier' Node listing their products, and an 'Attributes' node. Simply put, there are attributes to every Product produced by a supplier.There's only one field that could possibly link the two together, and that's Product_ID. However, multiple suppliers will have a product_id of 1, thus making the join in T-SQL tables impossible.Does SSIS in BIDS (which I'm relatively new too) have a function/feature/transformation, where by I can populate an Attributes table with all of it's corresponding data, while also inserting the supplier_id as an extra column.The supplier_id needs to come from the supplier node, while 'joining' the attributes table; so to speak.You would think this is somehow possible, based on the fact that the attributes node is always a node within the supplier node.Any help or guidance would be much appreciated.Cheers,-Ro</description><pubDate>Mon, 21 Nov 2011 17:55:12 GMT</pubDate><dc:creator>rhare</dc:creator></item><item><title>XML update using lots of attributes -- help!</title><link>http://www.sqlservercentral.com/Forums/Topic1207959-21-1.aspx</link><description>Good people:Here is my situation.  I have an ASP.NET Form with hundreds of input boxes that hold values for individual records.  I have a mechanism where I use the table key to name each textbox.  So, in the VB code, I can create an XML variable from this data.  It is my intention to pass it to the database via a stored procedure that looks something like this:[code="sql"]create proc spLoadIt ( @xml XML)asbegin    ???end[/code]The question marks are where I am having issues.  In fact, there are two of them, and I would really appreciate any help on either.1) I would like to construct the XML in the following fashion:[code="xml"]&amp;lt;mytable keya="101" keyb="A" keyc="1" value="8.33"&amp;gt;&amp;lt;mytable keya="102" keyb="A" keyc="3" value="22.5"&amp;gt;&amp;lt;mytable keya="103" keyb="M" keyc="4" value="0.18"&amp;gt;...[/code]In other words, have each element represent a single row and the attributes represent the columns -- a 3-part key and the value to store.  Is this feasible?2) In the upsert procedure, I would like to use the MERGE statement to make the insert/update procedure quick and painless.  Unfortunately, I lack the right knowledge to both put something together and find what I need online.  I get the basic syntax of the MERGE, but I don't know how to map the attributes in the elements to fields for use in the T-SQL code.  Anyone know how to do this?  My head is aching from all the google searching.</description><pubDate>Thu, 17 Nov 2011 14:55:39 GMT</pubDate><dc:creator>james.jensen1350</dc:creator></item></channel></rss>
