Friday, February 17, 2012

Dynamic attribute name

Hi,

I've tried following XQuery:

Code Snippet

declare @.rowoldXML xml;

declare @.attrValue nvarchar(max), @.cursorValue nvarchar(max);

declare @.s nvarchar(max);

SET @.rowoldXML = '<rowold Text="Hello"/>';

SET @.attrValue = '1.59'

SET @.cursorValue = 'Price';

SET @.rowoldXML.modify( 'insert attribute sql:variable("@.cursorValue"){sql:variable("@.attrValue")} into (/rowold)[1]' );

which gave me the error message : "XQuery [modify()]: "{" was expected."
Is there a way to dynamically name the attribute ( in my little sample @.cursorValue ) ?

TIA,

Karsten

It's not supported. The attribute or element name in the modify method must be constant.

You can use dynamic T-SQL to do this if you want.

No comments:

Post a Comment