2

I have a need to take the parameters passed in to a Stored Procedure (SQL 2005) and write those values into an XML column as one xml document.

Looking for an idea on how to start it.

0

1 Answer 1

2

Well, let's do this thing!

select 1 [one],2 [two],3 [three]
from  (select null dummy) t
for xml auto

and we get

<t one="1" two="2" three="3" />

Neat, eh?

You can also experiment with for xml path like so:

select 1[one],2[two],3[three]
from  (select null dummy) t
for xml path('foo')

And the result is:

<foo>
  <one>1</one>
  <two>2</two>
  <three>3</three>
</foo>
Sign up to request clarification or add additional context in comments.

3 Comments

+1: Without more detail, the TSQL FOR XML has numerous options to create XML.
Awesome. Thanks Denis. Now I'm playing with fire.
@tmercer: Yes, you are playing with fire, so be careful. See Brent Ozar's blog under the heading "Just Because You Can…." for some great comments on XML in the database.

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.