Solved

Insert into table from another table with an extra value

Posted on 2004-08-12
5
1,593 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:TDRXander
5 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 250 total points
Comment Utility
Create Stored procdure
 @User_ID int
AS
Insert into Table A (Select @user_ID, Value1,Value2,Value3 from Table B Where Table_B_ID  = 1)

0
 
LVL 18

Expert Comment

by:SjoerdVerweij
Comment Utility
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
0
 
LVL 11

Expert Comment

by:ram2098
Comment Utility
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

0
 
LVL 17

Expert Comment

by:BillAn1
Comment Utility
I assume here that Table_A_ID is a identity column, i.e. you don't have to give it any value?
0
 

Author Comment

by:TDRXander
Comment Utility
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!
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now