Your question suggests the use of a cursor. However, I think you may be able to use a virtual view. Try something like this
SUM(vw.TotPiece) AS Totals
SELECT MAX(RemoveDate) AS RemoveDate,
WHERE SetPosition = 'T1- 3.5'
AND EventType = 'Die'
GROUP BY LineNum, TotPiece
) AS vw
If you still need a cursor, the BOL is clear. Look for READ_ONLY cursor. From QA, you can also click on Object Browser (F8) and then on the Templates tab. Open the Using Cursors folder and drag the "Declare and use READ_ONLY cursor" element to your QA pane.
I'm sorry. I did poor job of explaining the details.
What I am trying to do is total the usage of a part. The part's life cycle is started at T1- 3.5 and continues to T2- 6.5. Each numeric value is a "move" of postion on the part. T1 is the first side. T2 is the second side. Typically the part is moved by .5 increments and would go T1- 3.5 to T1- 6.5 then rotated to T2- 3.5 to T2- 6.5. However, sometimes a position is skipped.
Data is stored in the table with a entry of each move along with production totals for each move.
Line = 1, DateRemoved = 10/27/04, SetPostion = T- 3.5, TotPiece = 10000
Line = 1, DateRemoved = 11/1/04, SetPostion = T- 4.0, TotPiece = 20000
Line = 1, DateRemoved = 11/5/04, SetPostion = T- 4.5, TotPiece = 30000
What I have been asked to do is display how much total production each part that is running has on it to date. Thus the Max(RemoveDate) with SetPostion = T1- 3.5 (last time a new set was installed). For the above example, I would get a return of DateRemoved 10/27/04 and TotPiece of 60000 for Line 1.
SELECT Hata_Meter_Records.Line, Last_Line_Changes.DateRemoved, SUM(Hata_Meter_Records.TotPiece) as TotPiece
(SELECT Line, Max(DateRemoved) DateRemoved
WHERE SetPostion = 'T- 3.5'
GROUP BY Line) Last_Line_Changes
on Hata_Meter_Records.Line = Last_Line_Changes.Line
and Hata_Meter_Records.DateRemoved >= Last_Line_Changes.DateRemoved
GROUP BY Hata_Meter_Records.Line, Last_Line_Changes.DateRemoved
If it's not practically useful, then it's practically useless.