?
Solved

take query results and append back to table

Posted on 2012-04-11
2
Medium Priority
?
248 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article I will describe the Copy Database Wizard 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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

800 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