views:

22

answers:

1

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.

+2  A: 

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>
Denis Valeev
+1: Without more detail, the TSQL [FOR XML](http://msdn.microsoft.com/en-us/library/ms190922.aspx) has numerous options to create XML.
OMG Ponies
Awesome. Thanks Denis. Now I'm playing with fire.
tmercer
@tmercer: Yes, you are playing with fire, so be careful. See [Brent Ozar's blog](http://www.brentozar.com/archive/2010/02/mcm-prep-week-microsoft-exam-70-433-and-70-451/) under the heading "Just Because You Can…." for some great comments on XML in the database.
Joe Stefanelli