0

我想以以下格式接收我的响应 XML...

<PersonDetails>
    <Name>Ajay</Name>
    <Age>29</Age>
    <ContactDetails>
        <ContactDetail>
            <ContactType>Mobile</ContactType>
            <ContactValue>9565649556</ContactValue>
        </ContactDetail>
        <ContactDetail>
            <ContactType>Email</ContactType>
            <ContactValue>ajay@yahoo.com</ContactValue>
        </ContactDetail>
    </ContactDetails>
</PersonDetails>

我在这里有 2 个不同的选择语句...

SELECT name, age FROM Person_Details
WHERE id = 12

SELECT Contact_Type, Contact_Value FROM Person_Contact_Details
Where id = 12

这里有任何建议...我尝试了 FOR XML EXPLICIT/PATH 的组合。

4

1 回答 1

5

PATH

SELECT name AS Name
            , age AS Age
            , (SELECT Contact_Type AS ContactType
                , Contact_Value AS ContactValue
                FROM Person_Contact_Details c
                WHERE c.id = p.id
                FOR XML PATH('ContactDetail'), TYPE) AS ContactDetails
        FROM Person_Details p
        WHERE id = 12
        FOR XML PATH('PersonDetails')
于 2009-06-16T08:19:24.730 回答