Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 openxml

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2007-02-27 : 07:39:49
Assuming there is a stored procedure with multiple OPENXML queries...
Is it necessary to have:

EXEC sp_xml_preparedocument @idoc OUTPUT, @XMLdoc
select ... from openxml...
EXEC sp_xml_removedocument @idoc

for each openxml or is it ok to have one of each in the whole of Stored proc?
Thanks

Kristen
Test

22859 Posts

Posted - 2007-02-27 : 09:01:23
You need a unique variable (e.g. @idoc) for each separate piece of XML - or you need to close one before opening the next with the same (@idoc) variable.

But I'm not sure I'm answering the right question?

Kristen
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2007-02-27 : 09:07:55
I was told by someone at Microsoft that only one EXEC sp_xml_preparedocument @idoc OUTPUT, @XMLdoc is required per document.

Since I am working on one document throughout the stored proc then no matter how many times I use openxml on that document then there is only a requirement to have one EXEC sp_xml_preparedocument @idoc OUTPUT, @XMLdoc
at the beginning of the stored proc and one EXEC sp_xml_removedocument @idoc
at the end of stored proc.
Something like:

EXEC sp_xml_preparedocument @idoc OUTPUT, @XMLdoc
select ... from openxml(Document1)...
select ... from openxml(Document1)...
select ... from openxml(Document1)...
EXEC sp_xml_removedocument @idoc
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-27 : 12:26:21
Yup, that looks fine to me. I wasn;t sure from your original post that you only have one XML document.

Kristen
Go to Top of Page
   

- Advertisement -