Is there a way to write a query that will eliminate the scan-endscan in the following code? The following code works but with large table it chews for a while.
Code:
*original table -
SET SAFETY off
CLOSE all
Create Table inter1 (slgno C(5), lots c(4))
Insert Into inter1 (slgno,lots) Values ('8001a',"")
Insert Into inter1 (slgno,lots) Values ('9001a',"")
Insert Into inter1 (slgno,lots) Values ('9001b',"")
Insert Into inter1 (slgno,lots) Values ('9001c',"")
Insert Into inter1 (slgno,lots) Values ('9001d',"")
Insert Into inter1 (slgno,lots) Values ('9002a',"")
Insert Into inter1 (slgno,lots) Values ('9002b',"")
Insert Into inter1 (slgno,lots) Values ('9002c',"")
Insert Into inter1 (slgno,lots) Values ('9003c',"")
Insert Into inter1 (slgno,lots) Values ('9003d',"")
*desired result is a second table
*lots.dbf with 2 fields slgno and lots
*with 3 records
*(slgno)(lots)
* 9001 abcd
* 9002 abc
* 9003 cd
Use Inter1
Set Unique On
Index On Substr(slgno,1,4) Tag lots
Set Order To lots
*we are creating labels for only section 9
Set Filter To Substr(slgno,1,1)=[9]
*put the lots into lots dbf so there is only one record for each lot instead of more
Copy To lots1 Fields slgno,lots
*use and index the new file lots on slgno
Use lots1
Index On slgno Tag slgno
Set Order To slgno
Goto Top
Do While .Not. Eof()
cLookup=Substr(slgno,1,4)
*create cursor with first lot number in it
Select * From Inter1 Where Substr(slgno,1,4)=cLookup Order By slgno Into Cursor temp
Select temp
cMv=[]
Scan
cMv=cMv+Substr(slgno,5,1)
Endscan
Select lots1
Replace lots With cMv
Skip
Endd
Brow && This is the desired output for reporting