Link to home
Start Free TrialLog in
Avatar of TDRXander
TDRXanderFlag for United Kingdom of Great Britain and Northern Ireland

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
ASKER CERTIFIED SOLUTION
Avatar of BillAn1
BillAn1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SjoerdVerweij
SjoerdVerweij

Create proc whatever
 @User_ID int
AS
Insert into Table A
Select @user_id, value1, value2, value3
from Table B Where Table_B_ID  = 1
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

I assume here that Table_A_ID is a identity column, i.e. you don't have to give it any value?
Avatar of TDRXander

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!