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
440 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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