I am reading XML data using OPENXML in a stored procedure in SQL Server 2012.
My XML:
<name>
<name>Temp1</name>
<data>
<mealID>5</mealID>
<food>
<foodID>11</foodID>
</food>
<food>
<foodID>12</foodID>
</food>
</data>
<data>
<mealID>6</mealID>
<food>
<foodID>13</foodID>
</food>
</data>
</name>
My stored procedure:
ALTER PROCEDURE [dbo].[sp_Insert_EatingProgramTemplate]
@Template xml,
@intOutSuccess nvarchar(10) OUTPUT,
@ErrorSeverity nvarchar(MAX) OUTPUT,
@ErrorMesg nvarchar(MAX) OUTPUT
AS
BEGIN
DECLARE @idoc int
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @ErrorSeverity = ''
SET @ErrorMesg = ''
SET @intOutSuccess = ''
BEGIN TRY
SELECT *
FROM OPENXML (@idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
SET @intOutSuccess = 1
END TRY
BEGIN CATCH
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorMesg = ERROR_MESSAGE()
SET @intOutSuccess = -1
GOTO A
END CATCH
A:
END
GO
While executing this procedure I am getting this error:
Could not find prepared statement with handle 0
Any help, why I am getting this error?
@idoc? Did you output it to see if it contained the value you expected? Also, did you consider just querying the XML directly instead of using OPENXML, sp_xml_preparedocument, etc.?nodes()XML function instead