keepingbusy
Programmer
All
Where to start?
Ok, I have a table with let's say 50 records. Within that table are some records (They are orders) from the same person for example three. All three seperate orders have different prices and different order requirements but I want to be able to merge the three orders into one, total the price and also the order details into that one memo field in one record.
I have found a way of using a Do while not eof() procedure that accomplishes this but it falls down when the procedure loops back to the original table.
Can this be done with an SQL statement or would anyone suggest this question is better placed in another forum? If so, please let me know.
This is what I have all be it, the long way around I'm sure.
The above works but when you go back to the original table, it looks for the next record which could have the same transaction number.
Some suggestions not the sollution would be very helpful guys.
Many thanks
Lee
Where to start?
Ok, I have a table with let's say 50 records. Within that table are some records (They are orders) from the same person for example three. All three seperate orders have different prices and different order requirements but I want to be able to merge the three orders into one, total the price and also the order details into that one memo field in one record.
I have found a way of using a Do while not eof() procedure that accomplishes this but it falls down when the procedure loops back to the original table.
Can this be done with an SQL statement or would anyone suggest this question is better placed in another forum? If so, please let me know.
This is what I have all be it, the long way around I'm sure.
Code:
tempfile=SYS(3)
USE TEMPDATA SHARED
COPY STRU TO WORKABLE
COPY STRU TO tempfile+'.dbf'
USE
CREATE TABLE TEMPMEMO (DETAILTEXT M)
USE TEMPMEMO SHARED
APPEND BLANK
USE
* SORT DUPLICATES
USE TEMPDATA SHARED
GO TOP
* The mtransact variable is the same when there
* is more than one order from the same person
DO WHILE NOT EOF()
STORE SPACE(40) TO mtransact
STORE TRANSACT TO mtransact
mrecno=0
mrecno=RECNO()
USE
SELECT * FROM TEMPDATA WHERE TRANSACT=mtransact ;
INTO TABLE tempfile+'.dbf'
STORE "" TO morderdesc
msubtotal=0
mshipping=0
mtotprice=0
USE tempfile+'.dbf' EXCL
GO TOP
DO WHILE NOT EOF()
mthis=0
mthis=RECNO()
STORE SPACE(120) TO morderdesc
STORE TRIM(COLUMN6)+" - SKU: "+TRIM(COLUMN8)+ ;
" - Price:"+STR(SUBTOTAL,7,2)+chr(13) TO morderdesc
USE TEMPMEMO SHARED
REPLACE DETAILTEXT WITH morderdesc ADDITIVE
USE
USE tempfile+'.dbf' EXCL
GO mthis
msubtotal=msubtotal+SUBTOTAL
mshipping=mshipping+SHIPPING
mtotprice=mtotprice+TOTPRICE
SKIP
ENDDO
USE TEMPMEMO SHARED
STORE SPACE(254) TO morder
STORE TRIM(DETAILTEXT) TO morder
* BY NOW THERE SHOULD ONLY BE ONE TOTAL RECORD
USE tempfile+'.dbf' EXCL
GO TOP
REPLACE SUBTOTAL WITH msubtotal
REPLACE SHIPPING WITH mshipping
REPLACE TOTPRICE WITH mtotprice
REPLACE DETAILTEXT WITH morder
DELE FOR RECNO()>1
PACK
* NOW APPEND THE ONE RECORD BACK TO THE
* WORKABLE TABLE SO THERE IS ONLY ONE
* RECORD THAT COULD CONTAIN MULTIPLE ORDERS
USE WORKABLE SHARED
APPEND FROM tempfile+'.dbf'
USE TEMPMEMO EXCL
REPLACE DETAILTEXT WITH ""
USE TEMPDATA EXCL && GO TO THE NEXT RECORD
GO mrecno
SKIP
ENDDO
Some suggestions not the sollution would be very helpful guys.
Many thanks
Lee