I have a table named VehicleHistoryBlob that has the following structure:
VehicleHistoryBlobId int PRIMARY KEY
VehicleHistoryBlob XML
I need to write SQL that finds all entries in VehicleHistoryBlob XML that have Bus as a parent node and Destination as a child node (Bus can have many Destinations, and the parent node in the XML is not always a Bus).
<Bus>
...
<Destination>
<Name>The big building</Name>
<DestinationCode> A21301423 </DestinationCode>
<DestinationAddress> 440 Mountain View Parade </DestinationAddress>
<DestinationCountry> USA </DestinationCountry>
</Destination>
</Bus>'
I need to query through the XML and find all entries that have Bus as a parent node and Destination as a child node, and pass the VehicleHistoryBlobId associated with the XML into my temporary table @tmpTable
DECLARE @tmpTable TABLE(theints INT)
I have been trying to manipulate the .nodes function but I am struggling to yield accurate results due to my lack of experience with XML as a data type.
Thanks in advance!