将文本附加到 FOR XML SQL Select 语句
来自 SQL nO0b 的您好,
我想要加入三个 Select
语句:
Select 2 是一个 FOR XML
Select,我想要将 Selects 1 和 Select 附加到该 Select 语句。 3(仅显示一些文本)作为一种页眉/页脚。
所有三个选择都按预期工作,并形成格式良好的播客 .xml 的三个部分,但我需要它们最终得到一个结果,以便我最终可以将其保存到一个 .xml 文件(我想这将是我的下一个头痛问题) )。
我尝试过我的经验不足的头脑可以想到的 +
、UNION
和 JOIN
的排列,但无济于事。
选择#1(仅一些文本)
Select '<?xml version=''1.0''?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<atom:link href="http://www.mysite.com/podcast/podcast.xml" rel="self" type="application/rss+xml" />
<itunes:image href="http://www.mysite.com/Portals/0/Images/Audio/podcast_logo.jpg"/>
<link>http://www.mysite.com/Audio.aspx</link>
<title>My Podcast</title>
<description>My Podcast's Description</description>
<language>en-us</language>
<copyright>© 2010</copyright>
<itunes:subtitle>Subtitle</itunes:subtitle>
<itunes:owner>
<itunes:name>Name</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<itunes:category text="Religion & Spirituality">
<itunes:category text="Christianity" />
</itunes:category>
<itunes:explicit>No</itunes:explicit>
<ttl> 120 </ttl>'
选择#2(我的数据)
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
选择#3(更多文本)
Select '</channel>
</rss>'
(我使用的是 MS SQLSMS 2008 .) (第二个 select 语句的复杂性是因为它从 DotNetNuke“用户定义的表/表单和列表”检索数据,该数据必须首先“展平”。)
任何帮助将不胜感激,谢谢。
Hello from an SQL nO0b,
I have three Select
statements I want to join:
Select 2 is a FOR XML
Select to which I want to append Selects 1 & 3 (which simply display some text) as a kind of header/footer.
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).
I have tried permutations of +
, UNION
, and JOIN
that my inexperienced mind can come up with, but to no avail.
Select #1 (simply some text)
Select '<?xml version=''1.0''?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<atom:link href="http://www.mysite.com/podcast/podcast.xml" rel="self" type="application/rss+xml" />
<itunes:image href="http://www.mysite.com/Portals/0/Images/Audio/podcast_logo.jpg"/>
<link>http://www.mysite.com/Audio.aspx</link>
<title>My Podcast</title>
<description>My Podcast's Description</description>
<language>en-us</language>
<copyright>© 2010</copyright>
<itunes:subtitle>Subtitle</itunes:subtitle>
<itunes:owner>
<itunes:name>Name</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<itunes:category text="Religion & Spirituality">
<itunes:category text="Christianity" />
</itunes:category>
<itunes:explicit>No</itunes:explicit>
<ttl> 120 </ttl>'
Select #2 (my data)
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
Select #3 (more text)
Select '</channel>
</rss>'
(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 & List" which must first be "flattened".)
Any help would be appreciated, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者,将 #1 和 #3 转换为 XML。
Alternatively, cast #1 and #3 to XML.