HI,
I'm have a problem with one proc. its very slow cause of condition while.
someone help me please?
WHILE EXISTS (SELECT 1 FROM @TMBENT WHERE K IS NULL)
BEGIN
DELETE @TMPAUX
INSERT INTO @TMPAUX(CHV,COD,SALDO) SELECT CHV,COD,K FROM @TMBENT Y
WHERE CHV=(SELECT MAX(CHV) FROM @TMBENT YI WHERE K IS NOT NULL AND YI.COD=Y.COD)
UPDATE @TMBENT SET K=SALDO+ISNULL(QE,0)-ISNULL(QS,0)-ISNULL(QP,0)
FROM @TMPAUX X,@TMBENT Y WHERE X.COD=Y.COD
AND Y.CHV=(SELECT MIN(CHV) FROM @TMBENT YI WHERE YI.COD=Y.COD AND YI.CHV>X.CHV)
END
tks;