
Select data from table and insert into another table


Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 27, 2015, 11:17 PM EST
try like
INSERT INTO tblnew
(column_name(s))
SELECT column_name(s)
FROM tblold;
Chathurika Palliyaguruge31 reputationPosted Jan 27, 2015, 11:24 PM EST
Syntax error in INSERT INTO statement
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 27, 2015, 11:28 PM EST
Chathurika Palliyaguruge31 reputationPosted Jan 27, 2015, 11:43 PM EST
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
con = New OleDbConnection(cs)
con.Open()
Dim cq As String = ("INSERT INTO Temp (Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total) SELECT Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total From Report WHERE Off_No='" + TextBox1.Text + "'")
cmd = New OleDbCommand(cq)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New OleDbConnection(cs)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
ReportOff_NoDateNameRankSumOfWineSumOfS/DrinkTotal
Chathurika Palliyaguruge31 reputationPosted Jan 28, 2015, 12:01 AM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 28, 2015, 12:11 AM EST
try another like
select Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total into
Temp from Report WHERE Off_No='" + TextBox1.Text + "'
Chathurika Palliyaguruge31 reputationPosted Jan 28, 2015, 12:43 AM EST
Jitendra KumarRank #760 · 3K reputationPosted Jan 28, 2015, 12:57 AM EST
Try this query :
"INSERT INTO Temp (Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total)
SELECT Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total From Report WHERE Off_No=''" + TextBox.Text + "''"
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 28, 2015, 12:57 AM EST
Chathurika Palliyaguruge31 reputationPosted Jan 28, 2015, 1:03 AM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 28, 2015, 1:15 AM EST
Chathurika Palliyaguruge31 reputationPosted Jan 28, 2015, 5:00 PM EST
Chathurika Palliyaguruge31 reputationPosted Jan 28, 2015, 5:04 PM EST
i try your code
showing this error
Syntax error in INSERT INTO statement
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 28, 2015, 5:51 PM EST
SELECT Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total From Report WHERE Off_No='" + TextBox.Text + "'
working fine for me
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Feb 25, 2015, 7:58 AM EST
Chathurika Palliyaguruge
The correct syntax of command is
INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;
In your query i find that you are missing a parenthesis near table name . Please remove this mistake
after that If it is throwing error then please check sequence of column name in both table in your query if both table's column are not in same sequence then it will generate error