-3

I have 2 tables named Order details and project. I want to populate the data from these tables into a new table named production with selected fields from the other 2 tables. How do I do that?

1 Answers1

0
SELECT
Orders.Field1, Orders.Field2, Project.Field1
INTO Production 
FROM 
Orders,Project

Or use a join if there is a relation between Orders and Project.

SELECT
Orders.Field1, Orders.Field2, Project.Field1
INTO Production 
FROM 
Orders
INNER JOIN
Project
ON
Orders.Field3 = Project.Field2
Robert Calhoun
  • 4,823
  • 1
  • 38
  • 34
  • Thank you.In sql server 2008 I am not able to create a table named production with no attributes. whenever I write a query with just create table production; it returns an error. why is it so. My ultimate aim was just to create the table with the simple query and then insert the fields and values from the existing tables. – user3865419 Jul 22 '14 at 16:33
  • You always have to define at least one field in a table. `SELECT INTO` will create the table using fieldnames from the source tables. See http://technet.microsoft.com/en-us/library/ms190750(v=sql.105).aspx – Robert Calhoun Jul 22 '14 at 16:45