I have three tables:
- TB1 : P (p_id (pk),p_name,p_description)
- TB2: PV (pv_id (pk),p_id(fk),v_id(fk),cost)
- TB3: V (V_id (pk),name)
I have used below SQL Server stored procedure "Addp" which inserts p_name
and p_description
on being called.
CREATE PROCEDURE AddP
(@name CHAR(50),
@description VARCHAR(255))
AS
BEGIN
DECLARE @PCount INT
SELECT @PCount = Count(P_ID)
FROM P
WHERE P_Name= @name
IF @PCount = 0
BEGIN
INSERT INTO P(P_Name, P_Description)
VALUES(@name, @description)
END
RETURN @@IDENTITY
END
Now, I would like to create another procedure where I can insert "v_id" and cost along with "Addp" stored procedure.My second SP looks like following. My question is How should I call my first stored procedure into second new stored procedure. So that when I execute my second stored procedure I should be able to insert p_name,p_description,vi,cost everything in one shot?
CREATE PROCEDURE AddPWithV (@vi int, @cost decimal(12,4))
AS
BEGIN
INSERT INTO PV (V_ID, Cost)
VALUES(@vi, @cost)
Return @@IDENTITY
END;
I am new to stored procedure.So,please guide me through explanation. Any help is appreciated! Thanks in advance!