Getting Started with Adobe After Effects - Part 6: Motion Blur
Ask
Ask questions, discuss or help others by answering
Related Posts · View All
SQL Server 142
TSQL 76
SSRS 70
SSIS 66
XML 54

Top Categories · View All
SQL Server 142
TSQL 76
SSRS 70
SSIS 66
XML 54

CTE,XML Path

Dec 12 2011 12:00AM by tano   

Below is a simplified query that returns the records for a single engine (serializedpartid='14549') I'd like to modify it to return all engines in the Engines table, creating an engine node for each engine and single fleet parent node. Replacing 'serializedpartid = '14549' with 'serializedpartid = (Select serializedpartid from engines) returns all the parts but puts them all in a single engine node.
I realize I can make this a procedure and call it multiple times but was hoping for something more selfcontained. Thanks in advance for your help.

with PartTree (Serializedpartid,partnumber,sn) AS
(
select 
    serializedpartid,
    PartsMaster.PartNumber,
    sn
 from SerializedParts
    Inner Join PartsMaster on PartsMaster.PartId = SerializedParts.PartId   
    where SerializedPartId = '14549' 
UNION ALL
Select 
    serializedparts.serializedpartid,
    PartsMaster.PartNumber,
    SerializedParts.sn
    from SerializedParts Inner Join
PartTree on serializedparts.nhserializedpartid = PartTree.SerializedPartId
    Inner Join PartsMaster on PartsMaster.PartId = SerializedParts.PartId
)
SELECT (
SELECT  	partnumber as '@partnum',
    		sn AS '@sn' 
    FROM    PartTree AS Engine
    FOR XML PATH('Parts'),TYPE)AS Engine
For XML PATH(''),ROOT('Fleet')

Submitted under: Microsoft SQL Server · XML ·  ·  · 


tano
431 · 0% · 91

1 Replies

  • It is really helpful if you can post some sample data and the structure of the expected XML output. That will help some on this forum to help you resolve this problem.

    commented on Aug 18 2012 8:17AM
    Jacob Sebastian
    1 · 100% · 32004

Your Reply


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]