Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Setting the value of an XML attribute using a relational variable


Setting the value of an XML attribute using a relational variable

Author
Message
Lempster
Lempster
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2683 Visits: 1657
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.

DECLARE @FullPathAndName varchar(100)  
SET @FullPathAndName = 'C:\DBA_Share\SSRS\Output\MyReport.rpt'



DECLARE @xVar XML 
SET @xVar =
'<package name="\File System\ReportToExcel" owner="sa" runAs="">
<variable name="Cnfg_ReportPath" value="C:\DBA_Share\SSRS\"/>
   <variable name="vSourceQuery" value="select * from dbo.sometable"/>
   <variable name="vFileName" value="@FullFileName"/>
</package>'



I know it is possible to use {sql:variable} when building an xml fragment from a query, e.g.

DECLARE @price money=2500.00
SELECT ProductID, Production.ProductModel.ProductModelID,CatalogDescription.query('
declare namespace pd="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";

<Product
ProductID="{ sql:column("Production.Product.ProductID") }"
ListPrice="{ sql:column("Production.Product.ListPrice") }"
DiscountPrice="{ sql:variable("@price") }"
/>')
FROM Production.Product



..but that's not what I want to do here.

Thanks
Lempster
Arthur Olcot
Arthur Olcot
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 1777
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:


DECLARE @FullPathAndName varchar(100)
SET @FullPathAndName = 'C:\DBA_Share\SSRS\Output\MyReport.rpt'

DECLARE @xVar XML = ''

SELECT @xVar = @xVar.query('for $x in ("") return
<package name="\File System\ReportToExcel" owner="sa" runAs="">
<variable name="Cnfg_ReportPath" value="C:\DBA_Share\SSRS\"/>
   <variable name="vSourceQuery" value="select * from dbo.sometable"/>
   <variable name="vFileName" value="{sql:variable("@FullPathAndName")}"/>
</package>')

SELECT @xVar



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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search