I have xml similar like this:
<main>
<kim id="child1_id" name="this is child1" active="1" />
<kim id="Child2 id" name="this is child2" active="1" />
<lee id="child3_id" heigt="189" weight="70" />
</main>
with kim and lee is the name of tables in my database. Now I have to make a stored procedure to insert the value from the xml above to kim and lee. I can get the table name using OPENXML and I know that I can use query like this for inserting (for example) kim value:
declare @tempChild1 table(
id varchar(20),
name varchar(50),
active bit
)
select C.value('@id', 'varchar(20)') as id,
C.value('@name', 'varchar(50)') as name,
C.value('@active', 'bit') as active,
from @xml.nodes('/main/kim') t (C)
insert into child1
select *
from @tempChild1
The problem is, it's a dynamic xml and I don't know what tables would come from the xml, but I still have to make an insert query based on the xml. Is there any possibilities to do it in SQL? Can I make the statement like below from the xml above?
exec spx_kim @xml
exec spx_lee @xml
with @xml is the value of each kim and lee node in the xml.
I really appreciate every help you give me.