Click here to Skip to main content
11,580,926 members (66,921 online)
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 9: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 Frankie-C 195
1 OriginalGriff 184
2 F-ES Sitecore 80
3 Andy Lanng 75
4 Afzaal Ahmad Zeeshan 75
0 OriginalGriff 1,108
1 Sergey Alexandrovich Kryukov 785
2 Abhinav S 622
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
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