I have a stored procedure called clients
with 3 parameters: the first one for user input, and the last two are OUTPUT
parameters.
This is the code:
CREATE PROCEDURE clients
(@name NVARCHAR(100),
@id_client int OUTPUT,
@messg varchar(1) OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
BEGIN TRAN
IF NOT EXISTS (SELECT name FROM client WHERE name = @name)
BEGIN
INSERT INTO client(name) VALUES (@name);
SET @id_client = SCOPE_IDENTITY();
SET @messg = 'o'
COMMIT TRAN
END
ELSE
BEGIN
SELECT @id_client = id_client
FROM client
WHERE name = @name;
SET @messg = 'o'
COMMIT TRAN
END
END TRY
BEGIN CATCH
SET @messg = 'e'
ROLLBACK TRAN
END CATCH
END
I need to call this stored procedure from another the second one is called updateS
, and I'm trying the following:
CREATE PROCEDURE updateS
(@clientname VARCHAR(100))
AS
BEGIN
SET NOCOUNT ON;
DECLARE @id INT;
DECLARE @msg VARCHAR(1);
EXEC clients @clientname, @id, @msg; --Problem here to retrieve the id
END
This stored procedure has a parameter for the name of the client, but I need to retrieve the id of the client, but it doesn't work as I'm trying.
Basically I need to get the id and use it in the second stored procedure.
Any question post on comments.