SQL, XML Inserting multiple nodes

Rajgmc

New Member
I have the following xml that I want to insert into a database\[code\]<latestjourneys> <journey> <startLocation>London</startLocation> <endLocation>manchester</endLocation> <leavingDay> <mon>Yes</mon> <tue>No</tue> </leavingday> <journey> <journey> <startLocation>Liverpool</startLocation> <endLocation>Cardiff</endLocation> <leavingDay> <mon>Yes</mon> <tue>No</tue> </leavingday> <journey></latestjourneys>\[/code\]I am using the following sql\[code\]INSERT INTO test (startLocation,endLocation,mon,tue)SELECT X.product.query('startLocation').value('.', 'VARCHAR(255)'),X.product.query('endLocation').value('.', 'VARCHAR(255)'),X.product.query('Mon').value('.', 'VARCHAR(255)'),X.product.query('Tue').value('.', 'VARCHAR(255)')FROM (SELECT CAST(x AS XML) FROM OPENROWSET( BULK '#fileLocation#', SINGLE_BLOB) AS T(x)) AS T(x) CROSS APPLY x.nodes('latestjourneys/journey') AS X(product)\[/code\]When I use this code only the startLocation and endLocation get inserted. When I change the CROSS APPLY to\[code\]CROSS APPLY x.nodes('latestjourneys/journey/leavingDay') AS X(product)\[/code\]only the days get inserted.is there a way I can insert both pieces of data?Thanks in advnace
 
Back
Top