DECLARE @rut VARCHAR(8)
DECLARE @dv CHAR
DECLARE @ntotal INT
SET @rut = '4321'
SET @dv = '4'
SET @rut = REVERSE(@rut)
SET @ntotal = LEN(@rut)
DECLARE @n INT = 0
DECLARE @sumarut INT = 0
DECLARE @mul INT = 1
WHILE @n < @ntotal
BEGIN
SET @mul = @mul + 1
SET @sumarut = @sumarut + SUBSTRING(@rut,@n+1,1) * @mul
IF @mul = 7
BEGIN
SET @mul = 1
END
SET @n = @n + 1
END -- fin while
DECLARE @calcdv CHAR(2)
SET @calcdv = 11 - @sumarut % 11
IF @calcdv='10'
BEGIN
SET @calcdv='K'
END
ELSE IF @calcdv='11'
BEGIN
SET @calcdv='0'
END
print @calcdv
IF @calcdv = @dv
BEGIN
print 'El rut es válido'
END
ELSE
BEGIN
print 'El rut es inválido'
END
No hay comentarios.:
Publicar un comentario