trouble wtih function

G

giorgio rancati

Hi Alejandro,

try this.
----
Dim Rs As New ADODB.Recordset

Dim strId As String
strId = "65004205868"

Rs.Open "Select dbo.CPF_VALIDO('" + strId + "') As Result", _
CurrentProject.Connection

MsgBox "The result is: " & Rs!Result

Rs.Close

Set Rs = Nothing
 
A

alejandro

I have this function in SQL server , i enter a number ( Brazilian Citizen
ID) and answer me if this number is valid or not with a char

ALTER FUNCTION CPF_VALIDO

(@CPF VARCHAR(11))

RETURNS CHAR(1)


how i must to re-write the code for show a msgbox , talking if the number is
valid or not??? the full code of the function is down.


Dim confirma As Long
Dim rs As ADODB.Recordset
Dim controle As ADODB.Command
Dim vale As Variant

Set cn = CurrentProject.Connection
Set controle = New ADODB.Command
Set controle.ActiveConnection = cn
controle.CommandText = "select * from cpf_valido"
controle.CommandType = adCmdStoredProc
controle.CommandTimeout = 15
controle.Execute


Thansk by any kind of help

Alejandro Carnero

ALTER FUNCTION CPF_VALIDO

(@CPF VARCHAR(11))

RETURNS CHAR(1)

AS

BEGIN

DECLARE @INDICE INT,

@SOMA INT,

@DIG1 INT,

@DIG2 INT,

@CPF_TEMP VARCHAR(11),

@DIGITOS_IGUAIS CHAR(1),

@RESULTADO CHAR(1)


SET @RESULTADO = 'N'

/*

Verificando se os digitos são iguais

A Principio CPF com todos o números iguais são Inválidos

apesar de validar o Calculo do digito verificado

EX: O CPF 00000000000 é inválido, mas pelo calculo

Validaria

*/

SET @CPF_TEMP = SUBSTRING(@CPF,1,1)

SET @INDICE = 1

SET @DIGITOS_IGUAIS = 'S'

WHILE (@INDICE <= 11)

BEGIN

IF SUBSTRING(@CPF,@INDICE,1) <> @CPF_TEMP

SET @DIGITOS_IGUAIS = 'N'

SET @INDICE = @INDICE + 1

END;

--Caso os digitos não sejão todos iguais Começo o calculo do digitos

IF @DIGITOS_IGUAIS = 'N'

BEGIN

--Cálculo do 1º dígito

SET @SOMA = 0

SET @INDICE = 1

WHILE (@INDICE <= 9)

BEGIN

SET @Soma = @Soma + CONVERT(INT,SUBSTRING(@CPF,@INDICE,1)) * (11 - @INDICE);

SET @INDICE = @INDICE + 1

END

SET @DIG1 = 11 - (@SOMA % 11)

IF @DIG1 > 9

SET @DIG1 = 0;

-- Cálculo do 2º dígito }

SET @SOMA = 0

SET @INDICE = 1

WHILE (@INDICE <= 10)

BEGIN

SET @Soma = @Soma + CONVERT(INT,SUBSTRING(@CPF,@INDICE,1)) * (12 - @INDICE);

SET @INDICE = @INDICE + 1

END

SET @DIG2 = 11 - (@SOMA % 11)

IF @DIG2 > 9

SET @DIG2 = 0;

-- Validando

IF (@DIG1 = SUBSTRING(@CPF,LEN(@CPF)-1,1)) AND (@DIG2 =
SUBSTRING(@CPF,LEN(@CPF),1))

SET @RESULTADO = 'S'

ELSE

SET @RESULTADO = 'N'

END

RETURN @RESULTADO

END
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top