Solved

Insert into table from another table with an extra value

Posted on 2004-08-12
5
1,594 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
ID: 11785283
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
ID: 11785285
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
ID: 11785295
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
ID: 11785303
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
ID: 11791313
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

895 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

16 Experts available now in Live!

Get 1:1 Help Now