SQLTeam.com | Weblogs | Forums

How to copy data from Query to Table


Hi All,
I am totally newbie in this field and I need help. I've imported the data (10 tables) in SQL Server Management Studio from Excel file. All 10 tables have the same headers. Now I would like to merge all tables into one.
I've created Query for each table but don't know how to connect/copy data from Query to Table that I created in SQL.
Can someone help me? :slight_smile:

Thank you in advance.


If I understand you would use an INSERT INTO

INSERT INTO YourMergeTable (Col1, Col2, ....) SELECT Col1, Col2, ... FROM YourTable1; INSERT INTO YourMergeTable (Col1, Col2, ....) SELECT Col1, Col2, ... FROM YourTable2; INSERT INTO YourMergeTable (Col1, Col2, ....) SELECT Col1, Col2, ... FROM YourTable3; . . . INSERT INTO YourMergeTable (Col1, Col2, ....) SELECT Col1, Col2, ... FROM YourTable10;
There are other ways to do this with a UNION for example.


As I said, I don't know nothing about SQL but I need to switch to it. So, I have imported 10 Tables in SQL from Excel. My task is to make ONE table form these 10. I will accept any solution. :wink:

And, please can you explain me how to INSERT this as I am not familiar with SQL.


I've tried like this. Right click on my imported table ---> Script table as ---> INSERT TO ---> New Query Editor and I am stuck here.
Also when I save one Query and close it, how to find and start again that Query?

As you can see from this picture, I created dbo.md Table and insert headers in it. Now, I would like to copy all data from these 10 Tables into dbo.md. How to do that?


I managed somehow with your instruction from above, but how to open "md" Table and see the results?


SELECT TOP(10) * FROM [Data Store].dbo.md;

Notice the * really should be replace with the column list, but this is the simple way. The TOP(10) give the first 10 rows.
Since your new to SQL you may not know that the data is not always stored in the order it was inserted, so if you do not get the ten rows you think you will need an ORDER BY.


Thanks man. And one more question. I have created Query and executed it. Everything works fine but how to create Table from this Query or move the data from Query in new Table?

As you can see from the picture I have the results from the Query, but I would like to create table from this, but don't know how. Table will have the same Headers.