I am trying to create a single SQL Server stored procedure in which I can input my own `c_id` and `COST` along with my previously created SQL Server stored procedure.
My tables are as follows:
* TB1: A (a_id (pk), a_name, a_description, a_qh)
* TB2: AC (ac_id (pk), a_id(fk), c_id(fk), ac_cost)
* TB3: C (c_id (pk), c_name)
My previously created procedure looks like following:
** NEW UPDATED CODE:**
CREATE PROCEDURE test (@name char(30), @description varchar(255), @VEid INT, @Cost as int) as
BEGIN
DECLARE @A_id INT
INSERT INTO a(a_Name,a_description) VALUES (@name,@Description )
Select @A_id = a_ID from A where a_Name = @name
Insert into AC(cost, A_ID, C_ID) values(@Cost, @A_id, @VEid)
END
I would like to add that my A Table has below info.
a_id a_name a_description
1 Pen THIS IS PEN
2 pAPER IT IS PAPAR
3 GLASS IT IS gLASS
14 RUBBER THIS IS RUBBR
MY C table consist of
c_id c_name
1 name1
2 nam2
3 name3
My AC table has followinf info
ac_id cost a_id c_id
1 50.0000 1 NULL
2 45.0000 2 NULL
3 30.0000 3 NULL
4 55.0000 1 2
5 20.0000 14 2
6 60.0000 1 3
7 25.0000 14 3
UPDATED AC table after running below query
1 15.0000 1 NULL
2 15.0000 2 NULL
3 15.0000 3 NULL
4 55.0000 1 2
5 20.0000 14 2
6 60.0000 1 3
7 25.0000 14 3
This is NOT what I was looking for. I was trying to insert new row with following info in ac tble
ac_id cost a_id c_id
8 15 from a table 1
Thanks in advance!
What I have tried:
My dilemma is I am new to SQL Server stored procedures, and I am trying to insert my new 'c_id', and 'ac.cost' along with a_name and a_description. So, if you can guide me through explanation . That will be great.
After Executing below code my