Inquiridor
Outro Erro na Mesma Proc

Pergunta
-
-- Author: Carlos Andrade
-- Create date: 17/08/2010
-- Description: Teste Carga Inicial Veiculo TMP
-- =============================================
ALTER PROCEDURE [dbo].[sp_ssis_testeHistoricoVeiculo_TEMP]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @registroHistoricoVeiculoCONTEUDO varchar(384)DECLARE @registroHistoricoVeiculoID int
DECLARE @contadorHistoricoVeiculo int
DECLARE @hiv_pk_historicoVeiculos int
DECLARE @hiv_nm_anoReferencia smallint
DECLARE @hiv_nm_mesInicioPagamento tinyint
DECLARE @hiv_ds_ultimoDigitoPlaca tinyint
DECLARE @hiv_fk_codigoMunicipio smallint
DECLARE @hiv_fk_combustivel tinyint
DECLARE @hiv_fk_tipo tinyint
DECLARE @hiv_fk_especie tinyint
DECLARE @hiv_fk_categoria tinyint
DECLARE @hiv_fk_carroceria smallint
DECLARE @hiv_fk_situacao smallint
DECLARE @hiv_ds_situacaoTributaria smallint
DECLARE @hiv_ds_faixa smallint
DECLARE @hiv_ds_quantidadePassageiro tinyint
DECLARE @hiv_ds_sequencialDHF bigint
DECLARE cursorVeiculo CURSOR
LOCAL FORWARD_ONLY
FOR (
SELECT
chv_pk_cargaInicialHistoricoVeiculoTemporaria,
chv_ds_registro
FROM
tb_chv_cargaInicialHistoricoVeiculoTemporaria
WHERE
(chv_fg_ativo = 1 AND chv_fg_processado=0)
)OPEN cursorVeiculo FETCH NEXT FROM cursorVeiculo INTO @registroHistoricoVeiculoID,@registroHistoricoVeiculoCONTEUDO
WHILE @@fetch_status = 0BEGIN
SET @hiv_nm_anoReferencia = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,1,5)))SET @hiv_nm_mesInicioPagamento = CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,6,5)))
SET @hiv_ds_ultimoDigitoPlaca = CONVERT (tinyint, dbo.fnFormataRegistroVarchar(substring(@registroHistoricoVeiculoCONTEUDO,11,1)))
SET @hiv_fk_codigoMunicipio = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,12,5)))
SET @hiv_fk_combustivel = CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,17,2))) -- ele reconhe esta linha como 72
SET @hiv_fk_tipo = CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,19,2)))
SET @hiv_fk_especie = CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,21,2)))
SET @hiv_fk_categoria = CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,23,2)))
SET @hiv_fk_carroceria = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,25,3)))
SET @hiv_fk_situacao = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,28,3)))
SET @hiv_ds_situacaoTributaria = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,31,3)))
SET @hiv_ds_faixa = CONVERT (smallint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,34,7)))
SET @hiv_ds_quantidadePassageiro= CONVERT (tinyint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,41,2)))
SET @hiv_ds_sequencialDHF = CONVERT (bigint, dbo.fnFormataRegistroNumeric(substring(@registroHistoricoVeiculoCONTEUDO,43,11)))
-- VERIFICANDO SE FOI ENVIADO A CHAVE UNICAIF (@hiv_ds_sequencialDHF IS NOT NULL)
BEGIN
INSERT INTO tb_hiv_historicoVeiculos
(hiv_nm_anoReferencia
,hiv_nm_mesInicioPagamento
,hiv_ds_ultimoDigitoPlaca
,hiv_fk_codigoMunicipio
,hiv_fk_combustivel
,hiv_fk_tipo
,hiv_fk_especie
,hiv_fk_categoria
,hiv_fk_carroceria
,hiv_fk_situacao
,hiv_ds_situacaoTributaria
,hiv_ds_faixa
,hiv_ds_quantidadePassageiro
,hiv_ds_sequencialDHF
)
VALUES
(
@hiv_nm_anoReferencia,@hiv_nm_mesInicioPagamento
,@hiv_ds_ultimoDigitoPlaca
,@hiv_fk_codigoMunicipio
,@hiv_fk_combustivel
,@hiv_fk_tipo
,@hiv_fk_especie
,@hiv_fk_categoria
,@hiv_fk_carroceria
,@hiv_fk_situacao
,@hiv_ds_situacaoTributaria
,@hiv_ds_faixa
,@hiv_ds_quantidadePassageiro
,@hiv_ds_sequencialDHF
)
SET @contadorHistoricoVeiculo = (@contadorHistoricoVeiculo+1)END
ELSE
PRINT '* O registro ' + convert(varchar(20),@registroHistoricoVeiculoID) + ' do CADASTRO DO HISTRICO DO VEICULO no possui CHAVE de pesquisa'
UPDATE
tb_chv_cargaInicialHistoricoVeiculoTemporaria
SET
chv_fg_processado=0,
chv_dt_alterado= GETDATE()
WHERE
chv_pk_cargaInicialHistoricoVeiculoTemporaria= @registroHistoricoVeiculoID
FETCH NEXT FROM cursorVeiculo INTO @registroHistoricoVeiculoID,@registroHistoricoVeiculoCONTEUDOEND
CLOSE cursorVeiculoDEALLOCATE cursorVeiculo
END
Todas as Respostas
-
Carlos,
Qual o erro que vc esta recebendo?
olhando sua proc, acredito que o cursor é desnecessário vc pode fazer o inert do select e o upate com o from
att.
Marcelo Fernandes
MCP, MCDBA, MCSA, MCTS.
Se útil, classifique!!!
Me siga no twitter: @marcelodba