我有以下要插入数据库的 xml
<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>
我正在使用以下 sql
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)
当我使用此代码时,只会插入 startLocation 和 endLocation。当我将 CROSS APPLY 更改为
CROSS APPLY x.nodes('latestjourneys/journey/leavingDay') AS X(product)
只有日子被插入。
有没有办法可以插入两条数据?