I have 2 stored procedures: up_proc1 and up_proc2.
This is (a simplified version of) up_proc2:
CREATE PROCEDURE dbo.up_proc2
@id_campaign uniqueidentifier, @id_subcampaign uniqueidentifier,
@id_lead uniqueidentifier, @offer NVARCHAR(1000) = NULL
AS
SET NOCOUNT ON
DECLARE @id UNIQUEIDENTIFIER
SELECT @id = id FROM prospects WHERE id_lead = @id_lead
AND id_campaign = @id_campaign AND id_subcampaign = @id_subcampaign
IF @id IS NULL
BEGIN
SET @id = newid ()
INSERT INTO prospects (id, id_campaign, id_subcampaign, id_lead, offer)
values (@id, @id_campaign, @id_subcampaign, @id_lead, @offer)
END
ELSE
BEGIN
UPDATE prospects set offer = @offer WHERE id=@id
END
SELECT @id AS ID
GO
From up_proc1 I call up_proc2. What I would like to achieve is to store the @id of up_proc2 in a variable declared in up_proc1. Is this possible without using an output parameter?
This is how up_proc1 looks like:
CREATE PROCEDURE dbo.up_proc1
AS
SET NOCOUNT ON
DECLARE @fromProc2 UNIQUEIDENTIFIER
-- NOT WORKING
-- select @fromProc2 = exec up_insertProspects [snip]
-- ALSO NOT WORKING
-- exec @fromProc2 = up_insertProspects [snip]
What you could do is store the output into a table variable:
and then go from there and use that table variable later on.