sql server - Format Table Variable Output with FOR XML AUTO -


Using SQL Server 2008.

I have a table variable with one column and one row.

If I do this:

  Announce the test breaks by inserting Test Testers in tables (testsId BigInt) @testsToRun where testId = 10 is selected I get the XML that looks like this:  
  

AutoType, type, root ('test message') from Top 1 * @tests to ToToRun XML, Code> & lt; Testmessage & gt; & Lt; _x0040_testsToRun testsId = "10" /> & Lt; / TestMessage & gt;

When I really want to:

  & lt; Testmessage & gt; & Lt; TestsToRun testID = "10" /> & Lt; / TestMessage & gt;  

If the row is the source table, then it seems to work fine. When this is a table variable, then I do not want any child element label that I do not want, I do not want testsToRun and _x0040_testsToRun

How do I work for my XML statement / clause to give me the proper output?

Thank you.

Try instead - use for XML path and you Define your output structure with the used column nickname (SES):

  SELECT TOP 1 testsId as '@testsId' to @TestRun for XML PATH ('testToRun'), root ('Testmessage')  

gives me:

  & lt; Testmessage & gt; & Lt; TestsToRun testID = "10" /> & Lt; / TestMessage & gt;  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -