FOR XML AUTO 的问题
Problems With FOR XML AUTO
我有以下查询:
SELECT QuestionID_PK ,
QuestionTitle ,
( SELECT dbo.Tags.TagID_PK ,
dbo.Tags.TagTitle ,
dbo.Tags.TagTitle_EN
FROM dbo.Question_Tag_Rel
INNER JOIN dbo.Questions
ON dbo.Question_Tag_Rel.QuestionID_FK = dbo.Questions.QuestionID_PK
INNER JOIN dbo.Tags
ON dbo.Question_Tag_Rel.TagID_FK = dbo.Tags.TagID_PK
AND dbo.Questions.QuestionID_PK = '2116'
FOR
XML PATH('') ,
TYPE ,
ELEMENTS
) AS Tags
FROM Questions
WHERE QuestionID_PK = '2116'
FOR XML AUTO ,
ELEMENTS;
产生这个 xml:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</Tags>
</Questions>
如您所见,我希望 (TagID_PK,TagTitle,TagTitle_EN) 标签位于父 XML 标签内,这是查询应输出的示例:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<tag>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
</tag>
<tag>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
</tag>
<tag>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</tag>
</Tags>
</Questions>
为了将它绑定到我的 ASP.NET 应用程序中的 Repeater,
你能帮我解决这个问题吗?
将XML PATH('')
更改为XML PATH('tag')
我有以下查询:
SELECT QuestionID_PK ,
QuestionTitle ,
( SELECT dbo.Tags.TagID_PK ,
dbo.Tags.TagTitle ,
dbo.Tags.TagTitle_EN
FROM dbo.Question_Tag_Rel
INNER JOIN dbo.Questions
ON dbo.Question_Tag_Rel.QuestionID_FK = dbo.Questions.QuestionID_PK
INNER JOIN dbo.Tags
ON dbo.Question_Tag_Rel.TagID_FK = dbo.Tags.TagID_PK
AND dbo.Questions.QuestionID_PK = '2116'
FOR
XML PATH('') ,
TYPE ,
ELEMENTS
) AS Tags
FROM Questions
WHERE QuestionID_PK = '2116'
FOR XML AUTO ,
ELEMENTS;
产生这个 xml:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</Tags>
</Questions>
如您所见,我希望 (TagID_PK,TagTitle,TagTitle_EN) 标签位于父 XML 标签内,这是查询应输出的示例:
<Questions>
<QuestionID_PK>2116</QuestionID_PK>
<QuestionTitle>Trying to find the execution time of my code using this</QuestionTitle>
<Tags>
<tag>
<TagID_PK>3</TagID_PK>
<TagTitle>جافا</TagTitle>
<TagTitle_EN>Java</TagTitle_EN>
</tag>
<tag>
<TagID_PK>8</TagID_PK>
<TagTitle>بايثون</TagTitle>
<TagTitle_EN>Python</TagTitle_EN>
</tag>
<tag>
<TagID_PK>9</TagID_PK>
<TagTitle>أندرويد</TagTitle>
<TagTitle_EN>Android</TagTitle_EN>
</tag>
</Tags>
</Questions>
为了将它绑定到我的 ASP.NET 应用程序中的 Repeater,
你能帮我解决这个问题吗?
将XML PATH('')
更改为XML PATH('tag')