
select data from table and insert into another table


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Feb 25, 2015, 12:58 PM
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
Khargesh RajputPosted Jan 28, 2015, 10:51 PM
SELECT Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total From Report WHERE Off_No='" + TextBox.Text + "'
working fine for me
Chathurika PalliyagurugePosted Jan 28, 2015, 10:04 PM
i try your code
showing this error
Syntax error in INSERT INTO statement
Chathurika PalliyagurugePosted Jan 28, 2015, 10:00 PM
Khargesh RajputPosted Jan 28, 2015, 6:15 AM
Chathurika PalliyagurugePosted Jan 28, 2015, 6:03 AM
Khargesh RajputPosted Jan 28, 2015, 5:57 AM
Jitendra KumarPosted Jan 28, 2015, 5:57 AM
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 + "''"
Chathurika PalliyagurugePosted Jan 28, 2015, 5:43 AM
Khargesh RajputPosted Jan 28, 2015, 5:11 AM
try another like
select Off_No,Name,Rank,SumOfWine,SumOfS/Drink,Total into
Temp from Report WHERE Off_No='" + TextBox1.Text + "'
Chathurika PalliyagurugePosted Jan 28, 2015, 5:01 AM
Chathurika PalliyagurugePosted Jan 28, 2015, 4:43 AM
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
Khargesh RajputPosted Jan 28, 2015, 4:28 AM
Chathurika PalliyagurugePosted Jan 28, 2015, 4:24 AM
Syntax error in INSERT INTO statement
Khargesh RajputPosted Jan 28, 2015, 4:17 AM
try like
INSERT INTO tblnew
(column_name(s))
SELECT column_name(s)
FROM tblold;