> I am trying to come up with a declare Cursor and fetch > command that will let me add the sum of the pieces needed for the various > dates and store each day in the table then move to the next code or piece of > equipment and do the same.
> SELECT SUM(QT1)INTO vQT1 FROM ORDEDTL WHERE vDATEchg BETWEEN vSTARTDTE AND > vENDDTE + > AND vCODE = CURRENT OF CURSOR > INSERT INTO EQUIP1 (PROJID, QT2, CODE, DATEUSED) #VALUES (.vPROJID, .vQT1, > .vCODE, .vDATEchg) You may be making this a good deal more complicated for yourself than necessary. You could try: SELECT MIN(STARTDTE)INTO vDATEchg FROM ORDERDTL INSERT INTO Equip1 (ProjID, Code, QT2, DateUsed) + SELECT ProjID, Code, SUM(QT1) .vDateChg + FROM OrderDtl + WHERE <<Something About Dates>> + GROUP BY ProjID, Code No DECLARE CURSOR, no loops, or anything. I had to put <<Something About Dates>> in the WHERE clause because I couldn't follow the logic and table structure from your post -- which tables have date columns and what they mean. If you post the table structures, I could try to finish off the INSERT statement. -- Larry
