EXEMPLO_1212310
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
SP_INSERTSTATUSBAIXATMOVLAN
Parameters
Name
Type
Mode
Definition
CREATE PROCEDURE SP_INSERTSTATUSBAIXATMOVLAN AS BEGIN DECLARE @CODCOLIGADA INTEGER DECLARE @IDLAN INTEGER DECLARE @STATUSLAN INTEGER DECLARE @IDLANREL INTEGER DECLARE @FINALIZAINTERACAO INTEGER DECLARE @IDLANMOVORIGEM INTEGER DECLARE @IDLANSEARCH INTEGER DECLARE IDLAN_CURSOR CURSOR FOR SELECT FLAN.CODCOLIGADA ,FLAN.IDLAN FROM FLAN WITH (NOLOCK) JOIN TMOVLAN WITH (NOLOCK) ON ( FLAN.CODCOLIGADA = TMOVLAN.CODCOLIGADA AND FLAN.IDLAN = TMOVLAN.IDLAN ) OPEN IDLAN_CURSOR FETCH NEXT FROM IDLAN_CURSOR INTO @CODCOLIGADA ,@IDLAN UPDATE FLAN SET FLAN.IDLANMOVORIGEM = FLAN.IDLAN FROM FLAN JOIN TMOVLAN ON ( TMOVLAN.CODCOLIGADA = FLAN.CODCOLIGADA AND TMOVLAN.IDLAN = FLAN.IDLAN ) WHILE (@@FETCH_STATUS = 0) BEGIN SET @IDLANREL = - 1 SET @STATUSLAN = - 1 SET @FINALIZAINTERACAO = 0 SET @IDLANMOVORIGEM = @IDLAN SET @IDLANSEARCH = @IDLAN WHILE (@FINALIZAINTERACAO <> 1) BEGIN SET @IDLANREL = ( SELECT FRELLAN.IDLANREL FROM FRELLAN WITH (NOLOCK) JOIN FLAN WITH (NOLOCK) ON ( FLAN.CODCOLIGADA = FRELLAN.CODCOLIGADA AND FLAN.IDLAN = FRELLAN.IDLAN AND FRELLAN.TIPOREL = 11 ) WHERE FLAN.CODCOLIGADA = @CODCOLIGADA AND FLAN.IDLAN = @IDLANSEARCH ) IF (ISNULL(@IDLANREL, 0) > 0) BEGIN UPDATE FLAN SET IDLANMOVORIGEM = @IDLANMOVORIGEM WHERE CODCOLIGADA = @CODCOLIGADA AND IDLAN = @IDLANREL SET @IDLANSEARCH = @IDLANREL SET @IDLANREL = - 1 END ELSE BEGIN SET @FINALIZAINTERACAO = 1 END END SET @STATUSLAN = ( SELECT STATUSLAN FROM FLAN WITH (NOLOCK) WHERE CODCOLIGADA = @CODCOLIGADA AND IDLAN = @IDLANSEARCH ) IF (@STATUSLAN = 1) BEGIN UPDATE TMOVLAN SET STATUSBAIXA = 1 WHERE CODCOLIGADA = @CODCOLIGADA AND IDLAN = @IDLAN END FETCH NEXT FROM IDLAN_CURSOR INTO @CODCOLIGADA ,@IDLAN END CLOSE IDLAN_CURSOR DEALLOCATE IDLAN_CURSOR END