Server: SQL Server 2019
In this edition, I am inserting a new record into a table using a named query and a stored procedure. The SP returns two values, the record ID and another Integer.
I would like to be able to retrieve both values and use them in the rest of the process. The record ID will be used as the user adds additional information into associated tables.
This is the code I have so far:
params = {"p_Category":category, "p_Classification":classification, "p_Description":desc, "p_ShortDesc":shortDesc, "p_Stock":stocked, "p_Review":review}
returnNQ = system.db.runNamedQuery(namedQuery, params)
self.parent.parent.getChild("flx_InputArea").getChild("TabContainer").getChild("flx_General").getChild("coord_Left").getChild("TextArea_0").props.text = returnNQ
This is what is returned from returnNQ
[{"":4021}]
When I query the table, the other value has been created, and when I test the named query, i get both values back. 103854 and 4021.
Just to show the named query results from another insert:
Thoughts?
Edit:
this is the named query:
EXEC inv.usp_Item_NewInsert :p_Category, :p_Classification, :p_Description, :p_ShortDesc, :p_Stock, :p_Review
Edit 2:
This is the SP:
CREATE PROCEDURE [inv].[usp_Item_NewInsert]
-- Add the parameters for the stored procedure here
@Category INT,
@Classification INT,
@Description VARCHAR(255),
@ShortDesc VARCHAR(66),
@Stocked BIT = 0,
@Review BIT = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @Catalog INT
DECLARE @ItemId INT
SET NOCOUNT ON;
EXEC inv.usp_GenerateCatalogNumber01 @Cat = @Catalog OUTPUT
-- Insert statements for procedure here
BEGIN TRANSACTION
INSERT INTO inv.Items (CatalogNumber, [Description], CategoryID, ClassificationID, ReviewThisPart, Stocked)
VALUES (@Catalog, @Description, @Category, @Classification, @Review, @Stocked);
COMMIT TRANSACTION
BEGIN
SET @ItemId = (SELECT ItemID
FROM inv.Items
WHERE CatalogNumber = @Catalog)
END
SELECT @Catalog, @ItemId
END
GO