TDRXander
asked on
Insert into table from another table with an extra value
I want to create a stored procedure that selects from one table which matches the where clause say id = 1, and stores the data along with the parameter (@user_ID) into another table
Table A
Table_A_ID ---- User_ID ------ Value1 ------ Value2 ------- Value3
Table B
Table_B_ID ----- Value1 ----- Value2 ----- Value3
Create Stored procdure
@User_ID int
AS
Insert into Table A (Select from Table B Where Table_B_ID = 1)
(while inserting the @User_ID into the Table A User_ID column at the same time)
How is this to be done,
many thanks
Xander
Table A
Table_A_ID ---- User_ID ------ Value1 ------ Value2 ------- Value3
Table B
Table_B_ID ----- Value1 ----- Value2 ----- Value3
Create Stored procdure
@User_ID int
AS
Insert into Table A (Select from Table B Where Table_B_ID = 1)
(while inserting the @User_ID into the Table A User_ID column at the same time)
How is this to be done,
many thanks
Xander
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Create Stored procdure
@User_ID int
AS
Insert into Table A
(Select
@userid,
value1,
value2,
value3
from Table B Where Table_B_ID = 1)
Thanks - Ram
@User_ID int
AS
Insert into Table A
(Select
@userid,
value1,
value2,
value3
from Table B Where Table_B_ID = 1)
Thanks - Ram
I assume here that Table_A_ID is a identity column, i.e. you don't have to give it any value?
ASKER
Thanks for the reply guys, all three of you submitted it at the same time it seems but as BillAn1 posted first i will give the points to him.
P.s. Table_A_ID is the identity column yes..
Thanks
Xander
p.s. didnt realise it was *that* simple! doh!
P.s. Table_A_ID is the identity column yes..
Thanks
Xander
p.s. didnt realise it was *that* simple! doh!
@User_ID int
AS
Insert into Table A
Select @user_id, value1, value2, value3
from Table B Where Table_B_ID = 1