Solved

take query results and append back to table

Posted on 2012-04-11
2
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linked Server Issue with SQL2012 3 33
SQL Server 2012 r2 - Varible Table 3 43
MS SQL BCP Extra Lines Between Records 2 30
Linked Server - SP with Param to VIew 7 25
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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‚Ķ
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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