Re: compare 2 recordsets
- From: "RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx>
- Date: Sun, 30 Sep 2007 00:19:09 +0100
Have run your code now and although there is only one loop it is no faster than my code.
Maybe I could make it faster by testing against an array rather than the parent node recordset.
By the way I take back what I said about the recordset getting un-sorted. This was something
else.
Maybe it could be speeded up by using Seek.
Thanks again for all the trouble taken in looking at this.
Will see if there is a better way and come back.
RBS
"Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom> wrote in message news:%23ilb4QtAIHA.4836@xxxxxxxxxxxxxxxxxxxxxxx
"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message news:OwWCChmAIHA.1168@xxxxxxxxxxxxxxxxxxxxxxxYes, 2 databases, so I can't do it in SQL.
Why not?
Every database I know has a method of registering a 3rd party database with itself.
For SQL Server, it is stored producedure
sp_addlinkedserver
with arguments
sp_addlinkedserver [ @server = ] 'server'
[ , [ @srvproduct = ] 'product_name' ]
[ , [ @provider = ] 'provider_name' ]
[ , [ @datasrc = ] 'data_source' ]
[ , [ @location = ] 'location' ]
[ , [ @provstr = ] 'provider_string' ]
[ , [ @catalog = ] 'catalog' ]
After that I could do
DELETE FROM tablename where somefield IN (SELECT somefield FROM remoteserver.dbo.anothertablename)
Far quicker than the 2-recordset approach
But on the 2-recordset approach:
It is not a double loop.
It is a single loop anti-merge (and very fast).
Something like
===========================
IF not recA.EOF and not recB.EOF THEN
DO
If recA.Item.Fld1 < rec2.Item.FldB THEN
recA.Delete
recA.MoveNext
If recA.EOF THEN EXIT DO
ELSEIf recA.Item.Fld1 > recB.Item.Fld1 THEN
recB.MoveNext
If recB.EOF THEN EXIT DO
ELSE
' they are equal
recA.MoveNext
recB.MoveNext
If recA.EOF or recB.EOF THEN EXIT DO
END IF
LOOP
END IF
'Deal with the fact that recA may not be exhausted but recB must be (other case needs no consideration)
DO WHILE NOT recA.EOF
recA.Delete
recA.MoveNext
LOOP
=================================
Note you did not say if recA or recB could have repeated values
If they can I would change
ELSE
' they are equal
recA.MoveNext
recB.MoveNext
If recA.EOF or recB.EOF THEN EXIT DO
END IF
to
ELSE
' they are equal
recA.MoveNext
If recA.EOF THEN EXIT DO
END IF
so that all A's duplicate values match the B record
Stephen Howe
.
- References:
- compare 2 recordsets
- From: RB Smissaert
- Re: compare 2 recordsets
- From: Bob Barrows [MVP]
- Re: compare 2 recordsets
- From: RB Smissaert
- Re: compare 2 recordsets
- From: Stephen Howe
- compare 2 recordsets
- Prev by Date: Re: compare 2 recordsets
- Next by Date: Re: compare 2 recordsets
- Previous by thread: Re: compare 2 recordsets
- Next by thread: Re: compare 2 recordsets
- Index(es):
Relevant Pages
|