June 12, 2009 at 1:48 am
When I am creating a data in the XML document type in SQL. At the time of
executing the
sp_xml_preparedocument i am getting the error "Must declare the scalar variable @doc"
At the time of creating an internal representation of the xml document by
"exec sp_xml_preparedocument @doc output, @xmldoc
I am getting the error message:- Must declare the scalar variable "@doc"
please let me know what is to be done.
I have attached a file in which my code is written.
June 12, 2009 at 7:24 am
Can you include the full code with the sp_xml_preparedocument statement and also indicate how you are running the script?
I took your code and included sp_xml_preparedocument in the last line and seem to work ok without any errors when I executed the whole block together in Microsoft Sql*Server Management Studio Query analyser.
see below
DECLARE @DOC int
DECLARE @XMLDOC nvarchar(1000)
SET @XMLDOC = N'
'
exec sp_xml_preparedocument @doc output, @xmldoc
June 12, 2009 at 8:39 am
Assuming you're running on SS2K5 (since posted in 2K5 forum), you should look into XQuery instead of openxml.
Example:
DECLARE @XMLDOC xml
SET @XMLDOC = N'
'
SELECT
c.value('@CustomerID[1]','varchar(30)') AS CustID
FROM @XMLDOC.nodes('/ROOT/Customer') AS T(c)
/* result set
CustID
JH01
SG01
*/
For further details on how to use XQuery I recommend ther article series of J. Sebastian "XML Workshop", especially for a start http://www.sqlservercentral.com/articles/Miscellaneous/2996/.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply