"Must declare the scalar variable" error

Asked

Viewed 16,754 times

2

When I run the following Procedure, Sqlserver gives the error:

Must declare the scalar variable error "@VDIAPARALYZED".

Procedure:

BEGIN
SELECT @VDIAPARALISADO = COUNT(F.DATA)
FROM ED_FERIADO F
WHERE F.EDEMPRESA_ID = @PEDEMPRESA_ID
    AND F.GMUNICIPIO_ID = @PGMUNICIPIO_ID
    AND F.SECRETARIA_ID = @PSECRETARIA_ID
    AND F.ANO = @PANO
    AND F.TIPO IN ('6')
    AND F.DATA BETWEEN @DT_INICIO
        AND @DT_FIM
    AND F.DATA NOT IN (
        SELECT C.DATA
        FROM ED_CALENDAR C
        WHERE F.EDEMPRESA_ID = @PEDEMPRESA_ID
            AND F.GMUNICIPIO_ID = @PGMUNICIPIO_ID
            AND F.SECRETARIA_ID = @PSECRETARIA_ID
            AND F.ANO = @PANO
            AND F.DATA BETWEEN @DT_INICIO
                AND @DT_FIM
            AND C.TIPO_CALEN = @VTIPO_CALENDARIO
        )

            END
  • 3

    I do not think it should be closed, it is not a typo, but rather a lack of variable declaration, it can happen to other people.

3 answers

1

Missed adding at the beginning

DECLARE @VDIAPARALISADO INT
  • is already declared but I have declared as: DECLARE @VDIAPARALISADO NUMERIC = 0

0

You are trying to pass a set of records to a single variable. The @VDIAPARALYZED variable expects a Scalar value, that is, a single value.

-1

DECLARE @VARIAVEL TIPO(TAM)
SET @VARIAVEL = VALOR (SE ELA FOR RECEBER UM VALOR)

Browser other questions tagged

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