[dba-SQLServer] Duplicate records

Mark A Matte markamatte at hotmail.com
Tue Mar 18 17:32:55 CDT 2008


I get the data in a 2+gig text file...how do import without dups...I tried that first...and it just stopped the import?


> Date: Tue, 18 Mar 2008 14:42:07 -0700
> From: fhtapia at gmail.com
> To: dba-sqlserver at databaseadvisors.com
> Subject: Re: [dba-SQLServer] Duplicate records
>
> Cursors are slow, you could choose to place an index to prevent duplicates
> so duplicate information just never makes it into the table?
>
>
>
> On Tue, Mar 18, 2008 at 1:46 PM, Mark A Matte 
> wrote:
>
>>
>> Hello All,
>>
>> I have a large table that occasionally duplicates make it into. The 2
>> fields that make the record unique are Case_ID and Note_Seq_Nbr. The
>> duplicates are identical...so I have no primary key. I used the code below.
>> It doesn't run very fast...but it does the job of removing just the extra
>> records...
>>
>> Any thoughts,comments, or suggestions on making it faster/better...or a
>> totally different approach?
>>
>> Thanks,
>>
>> Mark A. Matte
>>
>>
>>
>> **********************BEGIN************************
>> --By Mark A. Matte 3/18/2008
>> declare @CaseID decimal(15,0), at NoteNum int, at NoteCount int
>> declare MyCursor cursor
>> for Select case_id,note_seq_nbr,count(*) as CT
>> from tblCaseNote_temp
>> group by case_id,note_seq_nbr
>> having count(*)>1
>> order by case_id,note_seq_nbr
>> open mycursor
>> fetch next from mycursor
>> into @CaseID, at NoteNum, at NoteCount
>> while (@@fetch_status =0)
>>
>> Begin
>> delete top(@noteCount-1) from tblCaseNote_Temp where
>> case_id=@CaseID and note_seq_nbr=@noteNum
>> fetch next from mycursor
>> into @CaseID, at NoteNum, at NoteCount
>> End
>> Close mycursor
>> deallocate mycursor
>> ***********************END*************************
>> _________________________________________________________________
>> Need to know the score, the latest news, or you need your Hotmail(R)-get
>> your "fix".
>> http://www.msnmobilefix.com/Default.aspx
>> _______________________________________________
>> dba-SQLServer mailing list
>> dba-SQLServer at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
>> http://www.databaseadvisors.com
>>
>>
>
>
> --
> -Francisco
> http://sqlthis.blogspot.com | Tsql and More...
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>

_________________________________________________________________
Shed those extra pounds with MSN and The Biggest Loser!
http://biggestloser.msn.com/



More information about the dba-SQLServer mailing list