Solved

take query results and append back to table

Posted on 2012-04-11
2
244 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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