Solved

Insert into table from another table with an extra value

Posted on 2004-08-12
5
1,595 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

786 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