Solved

take query results and append back to table

Posted on 2012-04-11
2
243 Views
Last Modified: 2012-06-21
sql server 2008

from query editor in mssql express


I have a query that is returning  records ok.

SELECT     dbo.CRS_Header.CRS_Project_Number, dbo.CRS_Header.CRS_Project_Type, dbo.CRS_Header.CRS_Project_State, dbo.CRS_Header.CRS_Cust_ID,
                      dbo.CRS_Header.CRS_Project_Start_Dt, dbo.CRS_Header.CRS_Project_End_Dt, dbo.CRS_Header.CRS_Num_Processed_Lns,
                      dbo.CRS_Header.CRS_SLS_Accum_Start_Dt, dbo.CRS_Header.CRS_SLS_Accum_End_Dt, dbo.CRS_Header.CRS_Report_Dt, dbo.CRS_Header.Load_Date,
                      dbo.CRS_Header.CRS_Cust_Assign, dbo.CRS_Header.CRS_Name, dbo.CRS_Header.CRS_Rep_End_Dt
FROM         dbo.CRS_HEADER_ARCHIVE RIGHT OUTER JOIN
                      dbo.CRS_Header ON dbo.CRS_HEADER_ARCHIVE.CRS_Project_Number = dbo.CRS_Header.CRS_Project_Number
WHERE     (dbo.CRS_HEADER_ARCHIVE.CRS_Project_Number IS NULL)


 I want to now take this result and INSERT into
dbo.CRS_HEADER_ARCHIVE   ??


Thanks
fordraiders
0
Comment
Question by:fordraiders
2 Comments
 
LVL 4

Accepted Solution

by:
quiklearner earned 500 total points
ID: 37834378
Since the table exists already, you will need to simply add an "insert into CRS_HEADER_ARCHIVE" in front of your select query. If you arent supplying the fields in exactly the same order as the table is defined or with different numbers of fields, you must supply the field list "(field1,field2)" for the insert between the insert and select (but make sure NOT to include the VALUES keyword):
http://msdn.microsoft.com/en-us/library/ms188263(SQL.105).aspx
http://msdn.microsoft.com/en-us/library/ms189872(SQL.105).aspx

BTW if the table didnt exist (obviously in your case it does because its being selected from in the query) this would be more simply done by doing a SELECT .... INTO statement:
http://msdn.microsoft.com/en-us/library/ms190750(SQL.105).aspx
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 37834527
perfect Thanks !
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now