I am looking at this tutorial
and it confuses me as I don’t get the SP
CREATE PROCEDURE [dbo].[spTEST_InsertXMLTEST_TEST](@UpdatedProdData nText)
AS
DECLARE @hDoc int
exec sp_xml_preparedocument @hDoc OUTPUT,@UpdatedProdData
INSERT INTO TBL_TEST_TEST(NAME)
SELECT XMLProdTable.NAME
FROM OPENXML(@hDoc, 'ArrayOfTBL_TEST_TEST/TBL_TEST_TEST', 2)
WITH (
ID Int,
NAME varchar(100)
) XMLProdTable
EXEC sp_xml_removedocument @hDoc
First I am using SQL 2005 and do I need to install something on the server to get OPENXML to work? Next I don’t get what these statements do
// not sure what @hDoc is for and why it is an int
DECLARE @hDoc int
// don't get what this is and where the output is.
exec sp_xml_preparedocument @hDoc OUTPUT,@UpdatedProdData
// don't get why it is "XMLProdTable" and if it always has to be like this
SELECT XMLProdTable.NAME
// pretty muct don't get anything what is happening after OPENXML
FROM OPENXML(@hDoc, 'ArrayOfTBL_TEST_TEST/TBL_TEST_TEST', 2)
WITH (
ID Int,
NAME varchar(100)
) XMLProdTable
// Don't know what this is really executing
EXEC sp_xml_removedocument @hDoc
Thanks
That will be used in the next call, it is an output parameter
It is calling the sp_xml_preparedocument, output just means it is an output parameter, @hDoc will be populated with the value in the proc
XMLProdTable is the alias used in the next part, the CTE is named XMLProdTable
It populates the CTE with values from the XML document under the ArrayOfTBL_TEST_TEST/TBL_TEST_TEST tag
This is releasing the document from memory
Take a look at the samples here http://msdn.microsoft.com/en-us/library/ms186918.aspx