SELECT ITEM_NO, INT((INVDATE - dtFirst)/7) AS WEEKNO , QTY ;
FROM INVDETL, INVHEAD ;
WHERE IN_PKEY = INHD_FKEY ;
AND INVDATE BETWEEN dtFirst AND dtLast ;
ORDER BY ITEM_NO ;
INTO CURSOR Temp1 NOFILTER
* At this point, we have all the applicable items regardless of customer
* with the item#, qty, and the week (the week estimate isn't what I'd do,
* but it matches what you laid out
SELECT ITEM_NO, SUM(QTY), WEEKNO ;
FROM Temp1 ;
INTO CURSOR Temp2 ;
GROUP BY ITEM_NO, WEEKNO NOFILTER
USE IN Temp1
* Now we have at most a record per item per week containing the number sold
CREATE CURSOR Temp3 (ITEM_NO C(4), WK1 I, WK2 I, WK3 I, WK43 I, WK5 I, WK6 I)
* make sure that the definition of ITEM_NO matches the field in your detail
* table
SELECT Temp2
GO TOP
INSERT INTO Temp3 (ITEM_NO) VALUES (Temp2.ITEM_NO)
LOCAL lcFldName && build the target field name using this variable
SCAN
IF Temp3.ITEM_NO # Temp2.ITEM_NO
INSERT INTO Temp3 (ITEM_NO) VALUES (Temp2.ITEM_NO)
ENDIF
lcFldName = 'Temp3.WK' + STR(Temp2.WEEKNO + 1,1)
REPLACE (lcFldName) WITH EVAL(lcFldName) + Temp2.QTY
ENDSCAN
USE IN Temp2
* Temp3 now contains the data that you want to report, sorted by ITEM_NOEMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater
NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC
The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys