Note that there are some explanatory texts on larger screens.

plurals
  1. POAppending Text to FOR XML SQL Select Statement
    text
    copied!<p>Hello from an SQL nO0b,<br> I have three <code>Select</code> statements I want to join: </p> <p>Select 2 is a <code>FOR XML</code> Select to which I want to append Selects 1 &amp; 3 (which simply display some text) as a kind of header/footer. </p> <p>All three Selects work as intended and form three parts of a nicely-formed podcast .xml, but I need them to end up in one result so I can eventually save it to an .xml file (which will be my next headache, I suppose). </p> <p>I have tried permutations of <code>+</code>, <code>UNION</code>, and <code>JOIN</code> that my inexperienced mind can come up with, but to no avail. </p> <p><strong>Select #1 (simply some text)</strong> </p> <pre><code>Select '&lt;?xml version=''1.0''?&gt; &lt;rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"&gt; &lt;channel&gt; &lt;atom:link href="http://www.mysite.com/podcast/podcast.xml" rel="self" type="application/rss+xml" /&gt; &lt;itunes:image href="http://www.mysite.com/Portals/0/Images/Audio/podcast_logo.jpg"/&gt; &lt;link&gt;http://www.mysite.com/Audio.aspx&lt;/link&gt; &lt;title&gt;My Podcast&lt;/title&gt; &lt;description&gt;My Podcast's Description&lt;/description&gt; &lt;language&gt;en-us&lt;/language&gt; &lt;copyright&gt;&amp;#xA9; 2010&lt;/copyright&gt; &lt;itunes:subtitle&gt;Subtitle&lt;/itunes:subtitle&gt; &lt;itunes:owner&gt; &lt;itunes:name&gt;Name&lt;/itunes:name&gt; &lt;itunes:email&gt;user@domain.com&lt;/itunes:email&gt; &lt;/itunes:owner&gt; &lt;itunes:category text="Religion &amp;amp; Spirituality"&gt; &lt;itunes:category text="Christianity" /&gt; &lt;/itunes:category&gt; &lt;itunes:explicit&gt;No&lt;/itunes:explicit&gt; &lt;ttl&gt; 120 &lt;/ttl&gt;' </code></pre> <p><strong>Select #2 (my data)</strong> </p> <pre><code>Select (Select Cast(FieldValue as nvarchar(max)) from dbo.UserDefinedData where UserDefinedFieldId = 305 and UserDefinedRowId = item.UserDefinedRowId) as [title] ,(Select 'Today''s Program is ' + Cast(FieldValue as nvarchar(max)) from dbo.UserDefinedData where UserDefinedFieldId = 305 and UserDefinedRowId = item.UserDefinedRowId) as [description] ,(Select Cast(Cast(FieldValue as nvarchar(max)) as DateTime) from dbo.UserDefinedData where UserDefinedFieldId = 306 and UserDefinedRowId = item.UserDefinedRowId) as [pubdate] ,(Select 'http://www.mysite.com/Portals/0/AudioFiles/RadioArchives/' + Cast(FieldValue as nvarchar(max)) from dbo.UserDefinedData where UserDefinedFieldId = 308 and UserDefinedRowId = item.UserDefinedRowId) as [guid] From dbo.UserDefinedRows item Where ModuleId = 820 and UserDefinedRowID in (select UserDefinedRowID from UserDefinedData where UserDefinedFieldID = 306 and Cast(Cast(FieldValue as nvarchar(max)) as DateTime) between '2010-Nov-11' and '2010-Nov-18') Order By [pubdate] DESC for XML AUTO,ELEMENTS </code></pre> <p><strong>Select #3 (more text)</strong> </p> <pre><code>Select '&lt;/channel&gt; &lt;/rss&gt;' </code></pre> <p>(I am using MS SQLSMS 2008.) (The complex nature of the second select statement is due to the fact that it is retrieving data from a DotNetNuke "User-Defined Table/Form &amp; List" which must first be "flattened".)</p> <p>Any help would be appreciated, Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload