0

INPUT:

SELECT EmpName AS [Name],
       EmpDOB       AS [Birthdate],
       EmpSalary        AS [WageAmount],
    Add1    AS [Address1],
    Add2    AS [Address2],
    Mobile  AS [Mobile]
FROM   Employee
FOR XML PATH

OUTPUT: (which works fine)

<Employee>
<Name>Conrad</Name>
<Birthdate>14-oct-76</BirthDate>
<WageAmount>10000</WageAmount>
<AdditionalInfo>
    <Address1>Washington DC</Address1>
    <Address2>DC</Address2>
    <Mobile>989898989</Mobile>
</AdditionalInfo>
</Employee>

I'm able to generate output - but i want this element to be added below mobile tag (CONTACT TYPE element - how can we add this)

<Mobile>989898989</Mobile>
**<ContactType><mobilephone/></ContactType>**

1 Answer 1

1
;WITH Employee AS (
SELECT  'Conrad' as EmpName,
        '14-oct-76' as EmpDOB,
        10000 as EmpSalary,
        'Washington DC' as Add1,
        'DC' as Add2,
        989898989 as Mobile
)

SELECT EmpName AS [Name],
       EmpDOB       AS [Birthdate],
       EmpSalary        AS [WageAmount],
    Add1    AS [AdditionalInfo/Address1],
    Add2    AS [AdditionalInfo/Address2],
    Mobile  AS [AdditionalInfo/ContactType/Mobile]
FROM   Employee
FOR XML PATH ('Employee')

Output:

<Employee>
  <Name>Conrad</Name>
  <Birthdate>14-oct-76</Birthdate>
  <WageAmount>10000</WageAmount>
  <AdditionalInfo>
    <Address1>Washington DC</Address1>
    <Address2>DC</Address2>
    <ContactType>
      <Mobile>989898989</Mobile>
    </ContactType>
  </AdditionalInfo>
</Employee>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.