2
我有一個爲我生成XML輸出的存儲過程。TSQL格式查詢輸出
的SP看起來是這樣的:
ALTER PROCEDURE [dbo].[InternFetchProf]
@positionID INT=''
AS
BEGIN
SET NOCOUNT ON;
BEGIN
SELECT A.[id],
A.[positionTitle],
(SELECT B.[id],
B.[question],
B.[order],
(SELECT D.[optionName],
D.[order]
FROM internshipProfOptions AS D
WHERE questionID = B.[id]
ORDER BY D.[order] ASC
FOR XML PATH ('optionsBlock'), TYPE, ELEMENTS, ROOT ('options'))
FROM internshipProfQuestions AS B
WHERE positionID = A.[id]
ORDER BY B.[order] ASC
FOR XML PATH ('questionBlock'), TYPE, ELEMENTS, ROOT ('questions'))
FROM internships AS a
WHERE A.[id] = @positionID
ORDER BY closeDate ASC
FOR XML PATH ('positions'), TYPE, ELEMENTS, ROOT ('root');
END
END
這給我的
<root>
<positions>
<id>1</id>
<positionTitle>APS Team</positionTitle>
<questions>
<questionBlock>
<id>1</id>
<question>Whats your fav color</question>
<order>1</order>
<options>
<optionsBlock>
<optionName>VBA</optionName>
<order>1</order>
</optionsBlock>
<optionsBlock>
<optionName>JavaScript</optionName>
<order>2</order>
</optionsBlock>
<optionsBlock>
<optionName>HTML</optionName>
<order>3</order>
</optionsBlock>
</options>
</questionBlock>
<questionBlock>
<id>2</id>
<question>Whos your daddy?</question>
<order>2</order>
<options>
<optionsBlock>
<optionName>PHP</optionName>
<order>1</order>
</optionsBlock>
<optionsBlock>
<optionName>Perl</optionName>
<order>2</order>
</optionsBlock>
</options>
</questionBlock>
</questions>
</positions>
</root>
我有一個額外的SELECT語句這裏的XML輸出:
SELECT C.[groupName],
C.[order],
FROM internshipProfGroups AS C
WHERE questionID = B.[id]
FOR XML PATH ('groupBlock'), TYPE, ELEMENTS, ROOT ('groups')
我正努力在「QuestionBlock」的根目錄下生成XML,如下所示:
<questionBlock>
...
<groups>
<groupBlock>
<groupName>Testing</groupName>
</groupBlock>
<groupBlock>
<groupName>Another Test</groupName>
</groupBlock>
</groups>
...
</questionBlock>
我很努力地在正確的領域得到這樣的陳述。對我可能錯過的任何幫助?