WHILE IN STORED PROCEDURE

  • 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;

  • Please read the first two articles I reference below regarding asking for assistance and performance problems. Please follow the instructions in those articles regarding what you should post to get the best help possible.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply