Skip to content

(mssql) Scalar and table variable not working unless directly above executing query #839

@arbonaa

Description

@arbonaa

Bug Description

Repro steps

  1. Add an empty line between scalar/table variable and the query.
  2. Select entire query as context and execute.

Ex.
DECLARE @year INT = 2024;
DECLARE @table TABLE (Brand NVARCHAR(255));

INSERT INTO @table
SELECT Brand
FROM dbo.cars
WHERE Year = @year

The above query fails because of the empty line between the variable declaration and the insert statement (used to work before).
Getting rid of the space or adding a comment appears appears to fix the issue.

Issue started when upgraded from 1.17.29 -> 1.17.30

Expected Behavior

The query should run if i select the entire statement, i.e. the variables should be in the context regardless of white space between them and the statement

Actual Behavior

Scalar and table variables not found in the execution context.

Environment

  • DBCode version: 1.17.37
  • VS Code (or fork) version: 1.106.0
  • OS: MacOS Tahoe 26.1
  • Database: MSSQL
  • Connection: (direct/SSH/SSL)

Error Meesages (if applicable)

Must declare the scalar variable "@Year".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions