I have the following tables with the following contents:

create table Employees (EmployeeID int primary key, EmployeeName varchar(10));

insert into Employees values (1, 'Employee1');

insert into Employees values (2, 'Employee2');

insert into Employees values (3, 'Employee3');


create table Orders (EmployeeID int, OrderName varchar(10) primary key);

insert into Orders values (1, 'Order1');

insert into Orders values (1, 'Order2');

insert into Orders values (1, 'Order3');

insert into Orders values (2, 'Order4');

And I want to retrieve the following query in XML

select EmployeeName, OrderName from Orders o, Employees e where o.EmployeeID = e.EmployeeID

The question, how can I save me the repeated EmployeeNames in XML? So that to have an output like:

    <orders>

    <employeename>Employee1

    <ordername>Order1</ordername>

    <ordername>Order2</ordername>

    <ordername>Order3</ordername>

    </employeename>

    <employeename>Employee2

    <ordername>Order4</ordername>

    </employeename>

    </orders>

asked 18 Sep, 05:24

Sarkis's gravatar image

Sarkis
547293764
accept rate: 20%

edited 18 Sep, 07:47

Volker%20Barth's gravatar image

Volker Barth
34.4k335490723

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×20

question asked: 18 Sep, 05:24

question was seen: 64 times

last updated: 18 Sep, 07:47