How to create a table, import joined columns, and insert the data in to the new table?
I have used a JOIN to put together a query that uses columns from multiple tables. I want to use that query to insert the appropriate data in a new table.
I see the columns I want and I know how to create a new table (before the join statements). I have seen many examples how to create the table and then the JOIN the columns. How do I get all 160k records in to that table?
OK here is the query I have so far....
-- Select appropriate columns
SELECT AP.[ApprovedID], AP.[TermID], AP.[SchoolID], AP.[CipCode]
, CX.[JobCode], DE.[DOECode], AP.[SA_Level], AP.[CreditHours]
, AP.[IsActive], AP.[NONVOCED], AP.[CreateDate], AP.[CreatedBy]
, AP.[LastUpdateDate], AP.[LastUpdatedBy], AP.[Designator], AP.[ChangeFlag]
-- Put it into a new table
开发者_如何学GoINTO [INTERS_2004].[inters].[inters_tblApprovedProgramsTest]
-- Put in the joins here
FROM [INTERS_2004].[inters].[inters_tblApprovedPrograms] AP
JOIN [INTERS_2004].[inters].[inters_tblCIPDOECrosswalk] CX
ON AP.[CipCode] = CX.[JobCode]
JOIN [INTERS_2004].[inters].[inters_tblDOECode] DE
ON CX.[DOECode] = DE.[DOECode]
ORDER BY AP.[ApprovedID]
....and at that point my knowledge fizzles in to the air...
Providing the table name you want to use does not already exist, use the SELECT ... INTO ...
syntax:
SELECT ...
INTO new_table
FROM Table1 t1
JOIN TABLE2 t2 ON t2.col = t1.col
WHERE ...
精彩评论