Solved

take query results and append back to table

Posted on 2012-04-11
2
242 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
Comment Utility
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
Comment Utility
perfect Thanks !
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

16 Experts available now in Live!

Get 1:1 Help Now