I have the following issue:
I have these 2 while loops that iterates through a node of an xml file but I can't see where to paste the while loop as it needs to be able to reference the xml nodes stated.
DECLARE @cnt INT = 1, @temprouteor varchar(50),@temproute varchar(50);
SET @cnt = 1
WHILE @cnt < COUNT(IDC.nodes('Segment/Leg'))-1
BEGIN
SET @temprouteor = @temprouteor + LORC.value('@CRSCode' , 'Varchar(50)' ) + '/'
SET @cnt = @cnt +1
END
WHILE @cnt = COUNT(IDC.nodes('Segment/Leg'))
BEGIN
SET @temproute = @temprouteor + LDESC.value('@CRSCode' , 'Varchar(50)' );
END
The 3 nodes are:
LEGC
LORC
LDESC
Does anyone have any ideas on how I can achieve this?
<Leg Ref="101" Direction="Outbound" Departure="2016-12-22T06:51:00" Arrival="2016-12-22T07:04:00" TransportMode="TRAIN">
<Origin UICCode="7034740" NLCCode="3474" CRSCode="TVP" Name="TIVERTON PARKWAY" />
<Destination UICCode="7034710" NLCCode="3471" CRSCode="TAU" Name="TAUNTON" />
<TOC Code="GW" Name="Great Western Railway" />
<Reservation PassengerRef="77814233" AccomodationUnit="B33" />
<TrainRoute Ref="101" OriginDeparture="2016-12-22T05:30:00" DestinationArrival="2016-12-22T09:21:00">
<Origin UICCode="7035800" NLCCode="3580" CRSCode="PLY" Name="PLYMOUTH" />
<Destination UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
</TrainRoute>
</Leg>
<Leg Ref="102" Direction="Outbound" Departure="2016-12-22T07:18:00" Arrival="2016-12-22T09:00:00" TransportMode="TRAIN">
<Origin UICCode="7034710" NLCCode="3471" CRSCode="TAU" Name="TAUNTON" />
<Destination UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<TOC Code="GW" Name="Great Western Railway" />
<Reservation PassengerRef="77814233" AccomodationUnit="D64" />
<TrainRoute Ref="102" OriginDeparture="2016-12-22T05:53:00" DestinationArrival="2016-12-22T09:00:00">
<Origin UICCode="7035800" NLCCode="3580" CRSCode="PLY" Name="PLYMOUTH" />
<Destination UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
</TrainRoute>
</Leg>
<Leg Ref="103" Direction="Outbound" Departure="2016-12-22T09:15:00" Arrival="2016-12-22T09:21:00" TransportMode="TRAIN">
<Origin UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<Destination UICCode="7030000" NLCCode="3000" CRSCode="AML" Name="ACTON MAIN LINE" />
<TOC Code="GW" Name="Great Western Railway" />
<TrainRoute Ref="103" OriginDeparture="2016-12-22T09:15:00" DestinationArrival="2016-12-22T09:40:00">
<Origin UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<Destination UICCode="7031360" NLCCode="3136" CRSCode="GFD" Name="GREENFORD" />
</TrainRoute>
</Leg>
<Leg Ref="601" Direction="Return" Departure="2016-12-22T14:33:00" Arrival="2016-12-22T14:42:00" TransportMode="TRAIN">
<Origin UICCode="7030000" NLCCode="3000" CRSCode="AML" Name="ACTON MAIN LINE" />
<Destination UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<TOC Code="GW" Name="Great Western Railway" />
<TrainRoute Ref="601" OriginDeparture="2016-12-22T14:16:00" DestinationArrival="2016-12-22T14:42:00">
<Origin UICCode="7031360" NLCCode="3136" CRSCode="GFD" Name="GREENFORD" />
<Destination UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
</TrainRoute>
</Leg>
<Leg Ref="602" Direction="Return" Departure="2016-12-22T15:06:00" Arrival="2016-12-22T17:18:00" TransportMode="TRAIN">
<Origin UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<Destination UICCode="7034740" NLCCode="3474" CRSCode="TVP" Name="TIVERTON PARKWAY" />
<TOC Code="GW" Name="Great Western Railway" />
<Reservation PassengerRef="77814233" AccomodationUnit="B84" />
<TrainRoute Ref="602" OriginDeparture="2016-12-22T15:06:00" DestinationArrival="2016-12-22T20:42:00">
<Origin UICCode="7030870" NLCCode="3087" CRSCode="PAD" Name="LONDON PADDINGTON" />
<Destination UICCode="7035260" NLCCode="3526" CRSCode="PNZ" Name="PENZANCE" />
</TrainRoute>
</Leg>
Expected output is to see a concatenated routing of all the legs of the train journey.
In this case: TVP/TAU/PAD/AML/PAD/TVP