Run an Append Query until the record count is null

Mohsin Malik

Registered User.
Local time
Today, 19:29
Joined
Mar 25, 2012
Messages
179
Hi, I have searched the internet to Run a query until the record count=0, i know that it may be done with loop, but did not know how can i do that? I want to run a query for insertion of data based on Criteria, the insertion of data is done on date basis, i want to run a loop to insert record until the record count =0, how to do this, thanks
 
Record count = 0 and record count Null are quite different.

In your loop scenario you have 2 recordsets.

1)The record set of values that may be inserted, and
2)The recordset into which some values will be inserted.

The general logic

Code:
Open recordset 1
Open recordset 2

Do while Recordset1.recordCount <>  0
Read recordset1
  If Criteria Means OK to Insert then
     Insert recordset1 record's data into  Recordset2 (append a record in recordset2)
  end if
Move to next recordset1 record
loop
Close recordset1
close recordset2

Good luck with your project.

Edit:

As Pat says you can do this with a query along this format (no looping)

Code:
Insert into myTable (fld1, fld2,fld3... fldx)
Select field1,field2,field3...fieldx From MyInputRecords
WHERE MyInputRecords.Fldx matches the criteria

see Example #2 at http://www.techonthenet.com/sql/insert.php
 
Last edited:

Users who are viewing this thread

Back
Top Bottom