Defining Archive tables predicate

My task is to archive records from these original tables to the archive tables as shown below; however the original tables have foreign keys define and table 2 has no date to be used in the INSERT where clause predicate -12 week. what would be your approach here, can you give me the directions and script.  thanks,
 



      Original Tables

(1)
CREATE TABLE [dbo].[JSServicesCheckListLog](
         [ServiceLogID],
      FK-[CSC],
      FK-[ServiceTypeID],
         [Comments],
         [ChecklistCompletedDate],
         [ChecklistCompletedBy],
         [CleaningDate],
         [NoShow],

(2)
CREATE TABLE [dbo].[JSServiceChecklistDetailsLog](
      PK-[ServiceDetailsLogId],
      FK-[ServiceLogID],
      FK-[ServiceWorkAreaDetailsID],
      FK-[RatingID],
         [Comments],



      Archive Tables

(1)
CREATE TABLE [Archive].[JSServicesCheckListLog](
      [JSServicesCheckListLogID],
      [ServiceLogID],
      [CSC],
      [ServiceTypeID],
      [Comments],
      [ChecklistCompletedDate],
      [ChecklistCompletedBy],
      [CleaningDate],
      [NoShow],
      [LastUpdateTimestamp],


                         
(2)

CREATE TABLE [Archive].[JSServiceChecklistDetailsLog](
      [JSServiceChecklistDetailsLogID],
      [ServiceDetailsLogId],
      [ServiceLogID],
      [ServiceWorkAreaDetailsID],
      [RatingID],
      [Comments],
      [LastUpdateTimestamp],
faith victoryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Since table 2 is based on table one you need to find the service logs within your 12 weeks and then join on the details table for anything you find.
0
faith victoryAuthor Commented:
The foreign keys in the two original tables are coming from different tables.  

Do I have to create foreign keys on the Archive Tables before joining to the original tables?
0
Kyle AbrahamsSenior .Net DeveloperCommented:
You shouldn't join Archive and Original

You should copy the header files from original to archive via an insert

You should copy the detail files from original to archive via an
insert into Archive.JSServiceChecklistDetailsLog select * from dbo.JSServiceChecklistDetailsLog d join dbo.JSServicesCheckListLog h on d.ServiceLogId = h.ServiceLogId where <conditions>

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

faith victoryAuthor Commented:
Hi Kyle,

Can you give me a script for this......how do you copy head first tgen details?
0
Kyle AbrahamsSenior .Net DeveloperCommented:
Hi Faith,

you can just do two insert statements
insert into archive.Header
select (...) from dbo.Header where ...
;

insert into archive.Details
select (...) from dbo.details d
join dbo.Header h on d.ForeignKey = h.PrimaryKey 
where <where clause from statemetn1>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
faith victoryAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.