1
How to Calculate the Nfe Key Checker Digit?
For example, which Key checker digit has 43 positions:
'2411050954052500019455001000000709124205076'
1
How to Calculate the Nfe Key Checker Digit?
For example, which Key checker digit has 43 positions:
'2411050954052500019455001000000709124205076'
0
Follows a code from a function that assists:
CREATE FUNCTION F_CHAVE_DFe_GERAR_ChaveSemDV(@ChaveSemDV nvarchar(43)) RETURNS nvarchar(44)
BEGIN
DECLARE
@Dv Nvarchar(1)
--- PEGO O TAMANHO DO NÚMERO DE ENTRADA
DECLARE @TamanhoDoCodigoSemDV INTEGER
SET @TamanhoDoCodigoSemDV = LEN(@ChaveSemDV)
-- CRIO UMA VARIÁVEL SOMATÓRIO
DECLARE @Soma INTEGER
SET @Soma = 0
--CRIO UM MULTIPLICADOR
DECLARE @Multiplicador INTEGER
SET @Multiplicador = 2
--CRIO UMA VARIÁVEL PARA FAZER O CALULO ATÉ O TAMANHO DO NUMERO DE ENTRADA
DECLARE @i integer
SET @i = 1
WHILE @i <= @TamanhoDoCodigoSemDV
BEGIN
--PRINT convert(varchar(3),@Multiplicador) + ' - ' + convert(varchar(3), @i) + ' - ' + (LEFT(RIGHT(@ChaveSemDV, @i),1))
SET @Soma = @Soma + (LEFT(RIGHT(@ChaveSemDV, @i),1) * @Multiplicador)
SELECT @Multiplicador =
CASE -- Reinicia o Multiplicador em 2 quando maior que 9
WHEN @Multiplicador < 9
THEN @Multiplicador + 1
ELSE 2 END
SET @i = @i + 1
END
--PRINT 'Soma: ' + CONVERT(varchar, @Soma)
SELECT @Dv = CASE WHEN @Soma%11 IN (0, 1) THEN 0 ELSE 11 - (@Soma%11) END
RETURN @ChaveSemDV + @Dv
END
Calling for:
SELECT F_CHAVE_DFe_GERAR_ChaveSemDV('2411050954052500019455001000000709124205076');
The result is:
24110509540525000194550010000007091242050760
Browser other questions tagged sql-server
You are not signed in. Login or sign up in order to post.
Are you in doubt as to what the calculation is, or is the question as to how to apply the calculation in
SQL Server
?– Homer Simpson
How to apply the calculation, but with the help of Digit Checker Calculation - SQL Server - iMasters Forum it was possible to identify a way, I will include as a response here!
– AndyDaSilva52