Cursor search: the number of variables declared in the INTO list must match the number of columns selected

Asked

Viewed 65 times

0

Hello!

I made a T-SQL and at the moment execute is giving the message:

Message 16924, Level 16, State 1, Line 58 Cursor search: the number of variables declared in the INTO list must match the number of columns selected.

Someone knows where I stand What’s wrong?

'''
    Declare @Seq INT, @ConfigAntiga INT, @ConfigNova INT,
    @Indicador Nvarchar(60),@ContabilCred int,@ContabilDeb int,@ContabilPessoa int,@rateio int,
    @ContabilHistorico nvarchar(1000),@FinancCred int,
    @FinancDeb int,@FinancHistorico nvarchar(1000),@CResultado int,
    @Formula nvarchar(500),@Acrescimo char(1),@Desconto char(1),
    @Visualizar char(1),@Ordem INT,
    @OperacaoAntiga INT, @Operacao INT
    
    SELECT @OperacaoAntiga = 36 --COLOCAR O SEQUENCIAL DA OPERAÇAO NA EMPRESA ANTIGA.
         , @Operacao = 498 --COLOCAR O SEQUENCIAL DA OPERAÇAO NA EMPRESA NOVA.
    
    
    DECLARE ConfigTributos CURSOR FOR
        
        Select Sequencial From ConfigTributos where Operacao = @OperacaoAntiga
        
    OPEN ConfigTributos 
        FETCH NEXT FROM ConfigTributos INTO @ConfigAntiga
        WHILE @@Fetch_Status <> -1 BEGIN        
        
            INSERT INTO ConfigTributos (Operacao,RegimeOrigem,RegimeDestino,TipoRecurso,Recurso,STICMS,BASEICMS,AliICMS,Substituicao,IsentosOutros,
            ContaDebFinICMS,ContaCredFinICMS,HistoricoFinICMS,ContaDebContabICMS,ContaCredContabICMS,HistoricoContabICMS,ApuraICMS,
            EnquadramentoIPI,STIPI,BaseIPI,AliqIPI,IncideIPI,ContaDebFinIPI,ContaCredFinIPI,HistoricoFinIPI,ContaDebContabIPI,
            ContaCredContabIPI,HistoricoContabIPI,ApuraIPI,STPIS,BasePIS,AliqPIS,IncidePIS,ContaDebFinPIS,ContaCredFinPIS,
            HistoricoFinPIS,ContaDebContabPIS,ContaCredContabPIS,HistoricoContabPIS,ApuraPIS,STCOFINS,BaseCOFINS,AliqCOFINS,
            IncideCOFINS,ContaDebFinCofins,ContaCredFinCofins,HistoricoFinCofins,ContaDebContabCofins,ContaCredContabCofins,
            HistoricoContabCofins,ApuraCofins,STPISS,BaseISS,AliqISS,IncideISS,ContaDebFinISS,ContaCredFinISS,HistoricoFinISS,
            ContaDebContabISS,ContaCredContabISS,HistoricoContabISS,ApuraISS,CRFinICMS,CRContabICMS,CRFinIPI,CRContabIPI,CRFinPIS,
            CRContabPIS,CRFinConfins,CRContabConfins,CRFinISS,CRContabISS,CFOPDentroEst,CFOPForaEst,CFOPImportExport,EstadoOrigemICMS,
            EstadoDestinoICMS,ListaServico,ContabICMS,ContabIPI,ContabPIS,ContabCOFINS,ContabISSQN,AliqSubstIcms,DeduzirICMS,DeduzirIPI,
            DeduzirPIS,DeduzirCOFINS,DeduzirISSQN,MVA,DiferencaICMS,BaseSubICMS,NatBcCredPis,NatBcCredCofins,NatCredPis,NatCredCofins,Descricao, UnidadeNegocio)
            
            Select @Operacao,RegimeOrigem,RegimeDestino,TipoRecurso,Recurso,STICMS,BASEICMS,AliICMS,Substituicao,IsentosOutros,
            ContaDebFinICMS,ContaCredFinICMS,HistoricoFinICMS,ContaDebContabICMS,ContaCredContabICMS,HistoricoContabICMS,ApuraICMS,
            EnquadramentoIPI,STIPI,BaseIPI,AliqIPI,IncideIPI,ContaDebFinIPI,ContaCredFinIPI,HistoricoFinIPI,ContaDebContabIPI,
            ContaCredContabIPI,HistoricoContabIPI,ApuraIPI,STPIS,BasePIS,AliqPIS,IncidePIS,ContaDebFinPIS,ContaCredFinPIS,
            HistoricoFinPIS,ContaDebContabPIS,ContaCredContabPIS,HistoricoContabPIS,ApuraPIS,STCOFINS,BaseCOFINS,AliqCOFINS,
            IncideCOFINS,ContaDebFinCofins,ContaCredFinCofins,HistoricoFinCofins,ContaDebContabCofins,ContaCredContabCofins,
            HistoricoContabCofins,ApuraCofins,STPISS,BaseISS,AliqISS,IncideISS,ContaDebFinISS,ContaCredFinISS,HistoricoFinISS,
            ContaDebContabISS,ContaCredContabISS,HistoricoContabISS,ApuraISS,CRFinICMS,CRContabICMS,CRFinIPI,CRContabIPI,CRFinPIS,
            CRContabPIS,CRFinConfins,CRContabConfins,CRFinISS,CRContabISS,CFOPDentroEst,CFOPForaEst,CFOPImportExport,EstadoOrigemICMS,
            EstadoDestinoICMS,ListaServico,ContabICMS,ContabIPI,ContabPIS,ContabCOFINS,ContabISSQN,AliqSubstIcms,DeduzirICMS,DeduzirIPI,
            DeduzirPIS,DeduzirCOFINS,DeduzirISSQN,MVA,DiferencaICMS,BaseSubICMS,NatBcCredPis,NatBcCredCofins,NatCredPis,NatCredCofins, Descricao, UnidadeNegocio
            FROM ConfigTributos where Sequencial = @ConfigAntiga    

            SELECT @ConfigNova = SEQUENCIAL From ConfigTributos where operacao = @Operacao 
            and RegimeOrigem =  ( SELECT RegimeOrigem From ConfigTributos where Sequencial = @ConfigAntiga)
            and RegimeDestino = ( SELECT RegimeDestino From ConfigTributos where Sequencial = @ConfigAntiga)
            and TipoRecurso =   ( SELECT TipoRecurso From ConfigTributos where Sequencial = @ConfigAntiga)
            and Recurso =       ( SELECT Recurso From ConfigTributos where Sequencial = @ConfigAntiga)        
          
            DECLARE AtualizaItens CURSOR FOR
            Select Indicador,ContabilCred,ContabilDeb,ContabilPessoa,ContabilHistorico,FinancCred,
            FinancDeb,FinancHistorico,CResultado,Formula,Acrescimo,Desconto,Visualizar,Ordem,@rateio,@rateio
            From IndicTributos Where SeqConfigTributos = @ConfigAntiga
            
            OPEN AtualizaItens 
                FETCH NEXT FROM AtualizaItens INTO  @Indicador ,@ContabilCred ,@ContabilDeb ,@ContabilPessoa ,
            @ContabilHistorico ,@FinancCred , @FinancDeb ,@FinancHistorico ,@CResultado ,
            @Formula ,@Acrescimo ,@Desconto , @Visualizar ,@Ordem ,@rateio
                WHILE @@Fetch_Status <> -1 BEGIN
                    
                    Select @Seq = Max(IsNull(Sequencial,0))+1 From IndicTributos
                    
                    Insert Into IndicTributos (Sequencial,Indicador,ContabilCred,ContabilDeb,ContabilPessoa,ContabilHistorico,FinancCred,
                    FinancDeb,FinancHistorico,CResultado,Formula,Acrescimo,Desconto,SeqConfigTributos,Visualizar,Ordem,Rateio)
                    
                    Select @Seq, @Indicador ,@ContabilCred ,@ContabilDeb ,@ContabilPessoa , @ContabilHistorico ,@FinancCred,
                    @FinancDeb ,@FinancHistorico ,@CResultado , @Formula ,@Acrescimo ,@Desconto, @ConfigNova , @Visualizar ,@Ordem,@rateio
                    
                FETCH NEXT FROM AtualizaItens INTO @Indicador ,@ContabilCred ,@ContabilDeb ,@ContabilPessoa ,
            @ContabilHistorico ,@FinancCred , @FinancDeb ,@FinancHistorico ,@CResultado ,
            @Formula ,@Acrescimo ,@Desconto , @Visualizar ,@Ordem ,@rateio
                END
            CLOSE AtualizaItens 
            DEALLOCATE AtualizaItens 
            
        FETCH NEXT FROM ConfigTributos INTO @ConfigAntiga
        END
    CLOSE ConfigTributos 
    DEALLOCATE ConfigTributos       
  • I think the message is clear. here: DECLARE AtualizaItens CURSOR FOR Select Indicador,ContabilCred,ContabilDeb,ContabilPessoa,ContabilHistorico,FinancCred, FinancDeb,FinancHistorico,CResultado,Formula,Acrescimo,Desconto,Visualizar,Ordem,@rateio,@rateio&#xA;From IndicTributos Where SeqConfigTributos = @ConfigAntiga you have 16 fields and ...

  • ... here: OPEN AtualizaItens FETCH NEXT FROM AtualizaItens INTO @Indicador ,@ContabilCred ,@ContabilDeb ,@ContabilPessoa ,@ContabilHistorico ,@FinancCred , @FinancDeb ,@FinancHistorico ,@CResultado , @Formula ,@Acrescimo ,@Desconto , @Visualizar ,@Ordem ,@rateio has 15 fields.

  • If the answer was helpful, be sure to accept it.

1 answer

1

In addition to being repeated, @rateio should simply be rateio in this part

DECLARE AtualizaItens CURSOR FOR
            Select Indicador,ContabilCred,ContabilDeb,ContabilPessoa,ContabilHistorico,FinancCred,
            FinancDeb,FinancHistorico,CResultado,Formula,Acrescimo,Desconto,Visualizar,Ordem,@rateio,@rateio

Browser other questions tagged

You are not signed in. Login or sign up in order to post.