There are several ways to do it:
Option #1:
Works with File->Open->Raw.xml
Select C.CategoryName, P.* from Category C inner join Product P on C.CategoryID = P.CategoryID
for xml raw('Category'), Root('Category')
Raw.xml:
<Category>
<Category CategoryName="Clothing" ProductID="1" ProductName="T-Shirt XL" Description="T-Shirt Extra Large" CategoryID="1" />
<Category CategoryName="Clothing" ProductID="2" ProductName="T-Shirt XL" Description="T-Shirt Extra Large" CategoryID="2" />
</Category>
Excel file open output:
CategoryName ProductID ProductName Description CategoryID
Clothing 1 T-Shirt XL T-Shirt Extra Large 1
Clothing 2 T-Shirt XL T-Shirt Extra Large 2
Option #2:
Works with Data->XML->Import->Auto.xml
Select C.CategoryName, P.* from Category C inner join Product P on C.CategoryID = P.CategoryID
for xml Auto, Root('Category')
Auto.xml:
<Category>
<C CategoryName="Clothing">
<P ProductID="1" ProductName="T-Shirt XL" Description="T-Shirt Extra Large" CategoryID="1" />
<P ProductID="2" ProductName="T-Shirt XL" Description="T-Shirt Extra Large" CategoryID="2" />
</C>
</Category>
Excel import output:
CategoryName ProductID ProductName Description CategoryID
Clothing 1 T-Shirt XL T-Shirt Extra Large 1
Clothing 2 T-Shirt XL T-Shirt Extra Large 2
Option #3:
To directly save the output to excel file:
open the command prompt and use the following command:
bcp "Select C.CategoryName, P.* from ADONETEntityTransactionTest.dbo.Category C inner join ADONETEntityTransactionTest.dbo.Product P on C.CategoryID = P.CategoryID" QueryOut d:\temp\ProductAndCategory.xls -T -S sr-corp-ezpdev\sqlexpress -c
Hope that helps!
Man2vb, if this helps please login to Mark As Answer. | Alert Moderator