I've a STORED PROCEDURE in which I've a table as follows:
CREATE TEMPORARY TABLE tt_ASSET_DETAILS
(
SiteGroup VARCHAR(30),
SiteNumber VARCHAR(50),
AssetCategory VARCHAR(30),
Address VARCHAR(50),
AssetName VARCHAR(50)
);
I want to insert data into this table from the following XML:
<ManageAsset>
<Asset>
<SiteGroup>Chicago</SiteGroup>
<SiteNumber>4524</SiteNumber>
<AssetCategory>Passenger Cars</AssetCategory>
<Address>Address 1</Address>
<AssetNumber>Tango</AssetNumber>
</Asset>
<Asset>
<SiteGroup>Cincinnati</SiteGroup>
<SiteNumber>5360</SiteNumber>
<AssetCategory>Passenger Cars</AssetCategory>
<Address>Address 2</Address>
<AssetNumber>Mango</AssetNumber>
</Asset>
</ManageAsset>
Now, I want the data between the node set <Asset> </Asset> to be inserted as first row and the other set of <Asset> </Asset> as second row.
For that I used the following code which is inserting both the sets of <Asset> </Asset> in a single row of the table,
INSERT INTO tt_ASSET_DETAILS(SiteGroup,SiteNumber,AssetCategory,Address,AssetName)
SELECT SiteGroup,SiteNumber,AssetCategory,Address,AssetNumber
FROM
(select ExtractValue(AssetsXML,'//ManageAsset/Asset/SiteGroup') as SiteGroup,
ExtractValue(AssetsXML,'//ManageAsset/Asset/SiteNumber') as SiteNumber,
ExtractValue(AssetsXML,'//ManageAsset/Asset/AssetCategory') as AssetCategory,
ExtractValue(AssetsXML,'//ManageAsset/Asset/Address') as Address,
ExtractValue(AssetsXML,'//ManageAsset/Asset/AssetNumber') as AssetNumber) XM;
Someone, Please help me in correcting my code so that my required result can be achieved!!!