Solved

Copy three months records of about 20 million of data from 200 million of records using the date range  and some where condition

Posted on 2011-02-22
3
429 Views
Last Modified: 2012-06-27
Hi I have a query where I have to copy the ~ 2 millions of records to another dummy table from 200 millions of records with some condition  with ID as Clustered Primary key

These are Based on two conditions:

1. Recent 3 months of data needs to be copied based on the date range... datatype is datetime which is in the form of following: '2010-02-11 01:25:00.670'

2. There is Description column which says 'Unknown Code 0'. Copy other than those records.

. How can I define the range of date by not hard coding the values I just want to pass the range of date by passing into variables using @min and @max

Is it easy to acheive using temp table or CTE's or is there any easy method that can copy huge data.

Thanks,


0
Comment
Question by:srionline2k6
3 Comments
 

Author Comment

by:srionline2k6
ID: 34950112
Thing to  add more. How can I define the range of date by not hard coding the values I just want to pass the range of date by passing into variables using @min and @max
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 34950749
Can't you have non-clustered index on your date column? Also if you can add description in include list of that non-clustered index. If so then u could use between construct in ur where clause to filter records for 3 months as per @min and @max along with description. You could temporarily hold these selected records in temp table that is again cluster indexed on ur Id. From there use them the way you desire.
0
 
LVL 9

Accepted Solution

by:
sureshbabukrish earned 125 total points
ID: 34951030
DECLARE @ReportStartDate DATETIME            
DECLARE @ReportEndDate DATETIME            
SET @ReportStartDate = DateAdd(M,-3,DateAdd(D,DateDiff(D,0,Getdate()),0))    
SET @ReportEndDate = DateAdd(MS,-3,DateAdd(D,DateDiff(D,0,Getdate()),0))    

the above date range gets last 3 months , if today date is 22nd feb, then nov22nd to feb 21st  will be pulled.

select * from  table1
where datecol between    @ReportStartDate,@ReportEndDate
and description <> 'Unknown Code 0'

above query will pull last three months data and can be used in any insert query or to create any view.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

830 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