Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to Improve Get_ROW_NUMBER with correlated

$
0
0

How to Improve this query please:

SELECT     FatherID, Date, Line, ProductCode, StockCode, QtyIn, QtyOut,
                          (SELECT     SUM(QtyIn - QtyOut) AS Expr1
                             FROM         (SELECT     ROW_NUMBER() OVER (ORDER BY Date, ID) AS Line, *
FROM         Test1) AS t1
                             WHERE     (Line <= t0.Line) AND (ProductCode = t0.ProductCode) AND (StockCode = t0.StockCode)) AS total, Type
FROM         dbo.test2 AS t0

-----------------

test2 is a view:

SELECT     ROW_NUMBER() OVER (ORDER BY Date, ID) AS Line, *
FROM         Test1


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>