Hallo,
ich habe folgendes Problem:
Ich möchte folgende Abfrage in eine UDF umwandeln, sodass ich die Variable @doc übergeben kann und den Select als Rückgabewert erhalte.
DECLARE @idoc int
DECLARE @doc varchar(2000)
SET @doc ='
<packmittel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="verpackungsregel.xs d">
<packmitteldaten>
<ARTIKEL>FMatte100</ARTIKEL>
<KARTIKEL>FMatte100</KARTIKEL>
<KAPAZITAET>87</KAPAZITAET>
</packmitteldaten>
</packmittel>'
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/packmittel/packmitteldaten',3)
WITH (ARTIKEL varchar(10),
KARTIKEL varchar(20),
KAPAZITAET varchar(10))
Leider bekomme ich es nicht hin. Wenn ich folgedes versuche bekomme ich die Meldung:Meldung 137, Ebene 15, Status 2, Prozedur udf_readPackregel, Zeile 16Die "@idoc"-Skalarvariable muss deklariert werden.
USE [Ref]
GO
-- ================================================
-- Template generated from Template Explorer using:
-- Create Inline Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[udf_readPackregel]
(
-- Add the parameters for the function here
@doc as varchar(2000)
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT *
FROM OPENXML (@idoc,'/packmittel/packmitteldaten',3)
WITH (ARTIKEL varchar(10),
KARTIKEL varchar(20),
KAPAZITAET varchar(10))
)
AS
BEGIN
declare @idoc as int
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
END
Kann mir jemand helfen?
Vielen Dank!!!
Gruß Stefan
ich habe folgendes Problem:
Ich möchte folgende Abfrage in eine UDF umwandeln, sodass ich die Variable @doc übergeben kann und den Select als Rückgabewert erhalte.
DECLARE @idoc int
DECLARE @doc varchar(2000)
SET @doc ='
<packmittel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="verpackungsregel.xs d">
<packmitteldaten>
<ARTIKEL>FMatte100</ARTIKEL>
<KARTIKEL>FMatte100</KARTIKEL>
<KAPAZITAET>87</KAPAZITAET>
</packmitteldaten>
</packmittel>'
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/packmittel/packmitteldaten',3)
WITH (ARTIKEL varchar(10),
KARTIKEL varchar(20),
KAPAZITAET varchar(10))
Leider bekomme ich es nicht hin. Wenn ich folgedes versuche bekomme ich die Meldung:Meldung 137, Ebene 15, Status 2, Prozedur udf_readPackregel, Zeile 16Die "@idoc"-Skalarvariable muss deklariert werden.
USE [Ref]
GO
-- ================================================
-- Template generated from Template Explorer using:
-- Create Inline Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[udf_readPackregel]
(
-- Add the parameters for the function here
@doc as varchar(2000)
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT *
FROM OPENXML (@idoc,'/packmittel/packmitteldaten',3)
WITH (ARTIKEL varchar(10),
KARTIKEL varchar(20),
KAPAZITAET varchar(10))
)
AS
BEGIN
declare @idoc as int
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
END
Kann mir jemand helfen?
Vielen Dank!!!
Gruß Stefan
Comment