I have XML data like this
DECLARE @input XML =
'<LicensingReportProcessResult>
<LicensingReport>
<Address key="3845HoopaLnLasVegasNV89169-3350U.S.A.">
<LineOne>3845 Hoopa Ln</LineOne>
<CityName>Las Vegas</CityName>
<StateOrProvinceCode>NV</StateOrProvinceCode>
<PostalCode>89169-3350</PostalCode>
<CountryCode>U.S.A.</CountryCode>
</Address>
<Person key="PersonPRI711284842">
<ExternalIdentifier>
<TypeCode>NAICProducerCode</TypeCode>
<Id>8001585</Id>
</ExternalIdentifier>
<BirthDate>1961-07-29</BirthDate>
</Person>
</LicensingReport>
</LicensingReportProcessResult>'
My T-SQL code to extract one specific set of elements:
-- extract into temp table
INSERT INTO #Address
SELECT
Tbl.Col.value('@Address', 'NVARCHAR(100)'),
Tbl.Col.value('@City', 'NVARCHAR(100)'),
Tbl.Col.value('@State', 'NVARCHAR(100)'),
Tbl.Col.value('@PostalCode', 'NVARCHAR(100)'),
Tbl.Col.value('@CountryCode', 'NVARCHAR(100)')
FROM
@xml.nodes('//LicensingReportProcessResult/LicensingReport/Address') Tbl(Col)
-- verify results
SELECT * FROM #Address
I want to insert different element data into separate tables. Like Address data into an Address table and Person data into a Person table. As new elements are added I want to save data into separate tables.
Can someone help?