I'm little confused... As i good
remember[
^] you are using MS SQL server to store data.
Comparing data on server side is much faster than comparing data on client side.
Have a look at below example:
DECLARE @tbl TABLE(LINE_NO VARCHAR(10), TotalOfLineNo INT, Percentage REAL)
INSERT INTO @tbl (LINE_NO, TotalOfLineNo, Percentage)
VALUES('23059B', 526, 0.006)
INSERT INTO @tbl (LINE_NO, TotalOfLineNo, Percentage)
VALUES('64006M', 2838, 0.001)
INSERT INTO @tbl (LINE_NO, TotalOfLineNo, Percentage)
VALUES('23059B', 526, 0.004)
SELECT t1.LINE_NO, t1.TotalOfLineNo, COALESCE(t1.P1,0) AS P1, COALESCE(t2.P2,0) AS P2, COALESCE(CONVERT(REAL, t1.P1 - t2.P2),0) AS PDiff
FROM (
SELECT LINE_NO, TotalOfLineNo, Percentage AS P1, ROW_NUMBER() OVER (ORDER BY Percentage DESC) + 1 AS RowNo
FROM @tbl) AS t1 LEFT JOIN (
SELECT LINE_NO, TotalOfLineNo, Percentage AS P2, ROW_NUMBER() OVER (ORDER BY Percentage DESC) AS RowNo
FROM @tbl) AS t2 ON t1.RowNo = t2.RowNo
result:
LINE_NO Total.. P1 P2 PDiff
23059B 526 0,006 0,004 0,002
23059B 526 0,004 0,001 0,003
64006M 2838 0,001 0 0
Is that what you want to achieve?