Solved

Insert into table from another table with an extra value

Posted on 2004-08-12
5
1,597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

733 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