Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Should I use SCAN, Locate or some other method here? 1

Status
Not open for further replies.

Steve688

IS-IT--Management
Oct 23, 2002
34
0
0
CA
I am working with a table that may have duplicate CONSTITID numbers in it. For the field 'CONSTITID' I need to start by counting how many times the ID occurs and write the count to a table. Right now I am ending up with a count of one everytime, even though I can see duplicate numbers because the table is sorted by that field and not keyed.

Code:
        rempsTC.open(":WORK:REMPSSA_WMS_BC.DB")	
	while not rempsTC.eot()
		cid1 =  rempsTC.CONSTITID
		numFound = 0
		scan rempsTC:
		     if rempsTC.CONSTITID = cid1 then
		        numFound = numFound + 1
    		     else
		     endIf
		endScan
		numTC.open(":WORK:NumFound.db")
		numTC.edit()
		numTC.insertAfterRecord()
		numTC."ConstitID" = cid1
		numTC."NumberFound" = NumFound
		rempsTC.nextrecord()
	endWhile
	msgInfo("Done","Done!")

Thanks in advance.

-Steve
 
How about
Code:
var
  qbe   query
endvar

qbe=query

EMPSSA_WMS_BC.DB | CONSTITID                              |
                 | check calc count all as numberFound    |

endQuery
qbe.executeqbe("numFound.db")




Tony McGuire
"It's not about having enough time. It's about priorities.
 
Thanks Tony.

I did try it with a query and 'calc count all' but I was missing the 'as numberFound' syntax.

That did the trick!

-Steve
 
Just so you can check it...

In your initial code you have a while loop.

Within that while loop, you are scanning that same table.

So the scan is going to cause the eot() to result in true after just ONE pass.

That is likely why you only ever got a count of one.




Tony McGuire
"It's not about having enough time. It's about priorities.
 
Okay, I think I understand. The SCAN has it's own built in While loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top