question

JINJOKU avatar image
JINJOKU asked

Stored Procedures with Output Parameters

  1. Stored Procedure with Output Parameters

a. Add a MgrID column to your emp table.
b. Populate it accordingly using the integer data type and same number of characters as the empID column
c. Build a SP that passes in empID and returns an output parameter of the mgrID - (Create the SP and verify it works correctly) (Keep in mind that the mgrID will also be an individual’s empID., since managers are also employees)
d. (Start a New Query and separate it from the previous Stored Procedure) Declare an empid int and manager_name Varchar (50) variable
e. Hard code your new empid variable and Pass it into your new SP to return the mgrid

(Use an actual empid in the variable location to test and Pass it into your new SP to return the mgrID)
f. Capture that mgrid in a variable and use that mgrid variable to determine the Managers name

(Create another statement which locates the Manager’s Name by using mgrID)
e. Print the Managers name

sqlteam
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JINJOKU avatar image JINJOKU commented ·

Please I need assistance writing these queries.

I have tried the following;



ALTER TABLE emp

ADD MgrID_1 INT;


UPDATE emp

SET MgrID_1 = empID;


CREATE PROCEDURE GetMgrID

@empID INT,

@mgrID_1 INT OUTPUT

AS

BEGIN

SELECT @mgrID_1 = MgrID_1

FROM emp

WHERE empID = @empID;

END;



DECLARE @empID INT, @manager_name VARCHAR(50);

SET @empID = 10; -- Replace with the desired empID


EXEC GetMgrID @empID, @mgrID_1 OUTPUT;


SELECT @manager_name = empName

FROM emp

WHERE empID = @mgrID_1;


PRINT @manager_name;


Error Message: "Must declare the scalar variable "@manager_name"."

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.