Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
I want to choose data from table1 + data from table2 & insert into table3.
 

Can somebody help me plssssss......
Posted 3-Jan-13 10:21am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try something like this,
 
INSERT INTO Table3 (Column1, Column2, Column3)
 
SELECT  a.Column1_1, a.Column2_1, b.Column2_2
FROM    Table1 a
JOIN    Table2 b
ON      a.Column1_1 = b.Column1_2
  Permalink  
Comments
Member 9693583 at 3-Jan-13 15:47pm
   
It is not working....
 
I m trying below code
 
protected void btnAllo_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("SERVER=KSHITIJA-PC; Initial Catalog=CRM;Integrated Security=True");
//SqlCommand cmd = new SqlCommand("Update Call_reg set status='Assigned' Where Complaint_no= '" + ddlComplaint.SelectedItem.ToString() + "'", con);
SqlCommand cmd = new SqlCommand(" insert into Call_Allocation values('select a.Fname from New_Tech a join Call_reg b on a.Fname=b.Complaint_no '", con);
try
{
con.Open();
 
int i = cmd.ExecuteNonQuery();
//int a = cmd1.ExecuteNonQuery();
if (i == 1)
{
ddlComplaint.SelectedItem.Text = "";
EO.Web.MsgBoxButton mb = new EO.Web.MsgBoxButton("OK");
MsgBox1.Show("Message: ", "Call Assigned to Technician", null, mb);
}
 
}
catch (Exception ex)
{
EO.Web.MsgBoxButton mb = new EO.Web.MsgBoxButton("OK");
MsgBox1.Show("Error: ", ex.Message, null, mb);
 
}
con.Close();
}
Sheikh Muhammad Haris at 3-Jan-13 19:48pm
   
You have to mention column names for your Call_Allocation table. Try this
 
SqlCommand cmd = new SqlCommand(" insert into Call_Allocation (Name)
select a.Fname from New_Tech a join Call_reg b on a.Complaint_no = b.Complaint_no ", con);
Sheikh Muhammad Haris at 3-Jan-13 19:49pm
   
Check your query in SQL Server Management Studio first.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

insert into table1(column1, column2)
select t1.col1, t2.col2 from table1 t1 inner join table2 t2 on t1.id = t2.id
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100