1

I am trying to build an xml by using the parameter value for the attribute.

Declare @price int =100

Declare @xml xml = '<Product DiscountPrice= "{sql:variable("@price")}"   />'

Select @xml

I get the following error.

Msg 9410, Level 16, State 1,
XML parsing: whitespace expected'

What am I missing here?

1 Answer 1

2

I believe sql:variable is only used within .query() calls. This is how you can create a snippet of xml using your variable:

Declare @price int =100
declare @xml xml;

set @xml = (select [@DiscountPrice] = @price for xml path('Product'));

Select @xml
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.