I’ve got a query that’s been driving me up the wall. The t-sql query is as follows but with about a thousand records in the source table, it’s taking forever and a day to run. Is there any faster way of accomplishing the same task anyone might think of:
SELECT *, ROUND((SELECT SUM(PartTotal)
FROM PartSalesRankings
WHERE Item_Rank <= sub.Item_Rank) /
(SELECT SUM(PartTotal)
FROM PartSalesRankings) * 100, 2) as Cum_PC_Of_Total
FROM PartSalesRankings As sub
I’m trying to classify my inventory into A,B, and C categories based on percentage of cost, but it needs to be a cumulative percentage of cost, ie. ‘A’ parts make up 80% of my cost, ‘B’ parts make up the next 15%, and ‘C’ parts are the last 5%. There’s obviously more to the sql statement than what I included, but the code I posted is the bottle-neck.
Any help would be greatly appreciated!
Aj
Sorry for the delay in response, but I’ve been up to my neck in other stuff, but after a great deal of trial and error I’ve found the following to be the fastest method: