我会将数据插入表格中。现在,一个存储过程使得如果该表中没有项目插入并返回该项目的id。我将在select
声明中使用此项目。
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getType]
@refType BIGINT,
@Name NVARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
IF(@refType = -1)
BEGIN
INSERT INTO IKRAM_TYPE ([Name])
VALUES(@Name)
SET @refType = SCOPE_IDENTITY()
END
RETURN @refType
END
控制项上方的存储过程,然后返回item的id。
另一个存储过程使用此ID但我无法执行此操作
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ikram_add]
@refPerson BIGINT,
@personels NTEXT,
@products NTEXT
AS
BEGIN
SET XACT_ABORT ON
DECLARE @refUser BIGINT, @ixml INT, @ixml2 INT
EXEC sp_xml_preparedocument @ixml OUTPUT, @personels
SELECT refPerso AS refPerso
INTO #PERSONELS
FROM OPENXML (@ixml, '/ROOT/PERSONEL', 1)
WITH (refPerso NVARCHAR(100) '@refPerso');
EXEC sp_xml_removedocument @ixml;
-- Verilerin isimlerinin tabloya xmlden aktarýmý
EXEC sp_xml_preparedocument @ixml2 OUTPUT, @products
SELECT
refType AS refType, TypeName AS TypeName,
[Count] AS [Count], Amount AS Amount
INTO #PRODUCTS
FROM OPENXML (@ixml2, '/ROOT/PRODUCT', 1)
WITH (refType BIGINT '@refType', TypeName NVARCHAR(50) '@typename', [Count] BIGINT '@count', Amount FLOAT '@amount');
EXEC sp_xml_removedocument @ixml2;
DECLARE @refIkram bigint,@refIkramType bigint
BEGIN TRANSACTION
INSERT INTO IKRAM (refUser)
VALUES (@refPerson)
SET @refIkram = SCOPE_IDENTITY()
INSERT INTO IKRAM_PERSONEL (refIkram, refPersonal)
SELECT @refIkram, p.refPerso
FROM #PERSONELS p
INSERT INTO IKRAM_PRODUCT (refIkram, refIkramType, [Count], Amount)
SELECT
@refIkram, getType(refType,TypeName), p.[Count], p.Amount
FROM
#PRODUCTS p
COMMIT TRANSACTION
SELECT 'SUCCEED' AS Result,@refUser AS RefUser
END
如何在select语句中调用第一个存储过程?第一个存储过程将返回id,我将使用此id插入第二个过程。我该怎么办?
提前致谢