I have come across a stored procedure that analyses and summarises existing data into a table ready for an export to a SQL Cube.
The problem is, it's all being slowed down by a cursor, but I don't really know how I can alter this to not use the cursor.
What it does is creates a temporary table that lists all of the ID's that need to be summarized.
A cursor is created from this temporary table that contains all of the references for each ID (an ID can have several references)
The reference has an amount, and the cursor will check the previous amount, and increment an Increase flag if the amount has increased, and increment a Decrease flag if it is lesser.
So the ID has amount of Increases and decreases saved to it, depending on the history of its references.
I can't really see a way in which the cursor can be written out, due to the task it has to perform, but I am not that experienced in SQL Server and was hoping someone on here who knows their stuff can tell me where I'm going wrong. I've attached the section of the stored procedure that needs to be re-written