﻿<?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  / Setting the value of an XML attribute using a relational variable / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 26 May 2013 02:22:38 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Setting the value of an XML attribute using a relational variable</title><link>http://www.sqlservercentral.com/Forums/Topic1385250-21-1.aspx</link><description>If i understand you correctly, you have an xml instance as a string which you want to assign directly to an xml variable whilst at the same time, populating some nodes in the xml string with other variables from the transaction scope? I'm probably not entirely understanding everything, but I have come up with this:[code="sql"]DECLARE @FullPathAndName varchar(100)  SET @FullPathAndName = 'C:\DBA_Share\SSRS\Output\MyReport.rpt'DECLARE @xVar XML = ''SELECT @xVar = @xVar.query('for $x in ("") return&amp;lt;package name="\File System\ReportToExcel" owner="sa" runAs=""&amp;gt;     &amp;lt;variable name="Cnfg_ReportPath" value="C:\DBA_Share\SSRS\"/&amp;gt; 	&amp;lt;variable name="vSourceQuery" value="select * from dbo.sometable"/&amp;gt;	&amp;lt;variable name="vFileName" value="{sql:variable("@FullPathAndName")}"/&amp;gt;&amp;lt;/package&amp;gt;')SELECT @xVar[/code]Does this help? if not, then if you can go into a bit more of the scenario that you have and what is your end goal.</description><pubDate>Thu, 15 Nov 2012 14:20:32 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>Setting the value of an XML attribute using a relational variable</title><link>http://www.sqlservercentral.com/Forums/Topic1385250-21-1.aspx</link><description>Is it possible to set the value of an XML attribute in an XML fragment using a relational variable that is declared and initialised elsewhere in the code block or stored procedure, e.g.[code="sql"]DECLARE @FullPathAndName varchar(100)  SET @FullPathAndName = 'C:\DBA_Share\SSRS\Output\MyReport.rpt'[/code][code="xml"]DECLARE @xVar XML SET @xVar = '&amp;lt;package name="\File System\ReportToExcel" owner="sa" runAs=""&amp;gt;     &amp;lt;variable name="Cnfg_ReportPath" value="C:\DBA_Share\SSRS\"/&amp;gt; 	&amp;lt;variable name="vSourceQuery" value="select * from dbo.sometable"/&amp;gt;	&amp;lt;variable name="vFileName" value="@FullFileName"/&amp;gt;&amp;lt;/package&amp;gt;'[/code]I know it is possible to use {sql:variable} when building an xml fragment from a query, e.g.[code="xml"]DECLARE @price money=2500.00SELECT ProductID, Production.ProductModel.ProductModelID,CatalogDescription.query('declare namespace pd="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";       &amp;lt;Product            ProductID="{ sql:column("Production.Product.ProductID") }"           ListPrice="{ sql:column("Production.Product.ListPrice") }"           DiscountPrice="{ sql:variable("@price") }"        /&amp;gt;') FROM Production.Product[/code]..but that's not what I want to do here.ThanksLempster</description><pubDate>Thu, 15 Nov 2012 09:40:22 GMT</pubDate><dc:creator>Lempster</dc:creator></item></channel></rss>