microsoft/SqlScriptDOM

ScriptDom parser for Sql Server 2022 fails to parse exec variable with version

Turyansky opened this issue · 2 comments

  • SqlPackage or DacFx Version: 161.6367.0-preview
  • .NET Framework (Windows-only) or .NET Core: .Net 6.0
  • Environment (local platform and source/target platforms): N/A

Steps to Reproduce:

  1. Create a new C# Console Project
  2. Add latest Nuget package for Microsoft.SqlServer.DacFx (161.6367.0-preview)
  3. Run code below
using Microsoft.SqlServer.TransactSql.ScriptDom;

var parser = new TSql160Parser(true); // Sql server 2022 parser

IList<ParseError> errors;

parser.Parse(new StringReader("CREATE PROCEDURE Proc1 AS EXEC ProcName;2"), out errors);
// No parsing errors

parser.Parse(new StringReader("CREATE PROCEDURE Proc1 AS DECLARE @ProcName SYSNAME = 'Proc2' EXEC @ProcName"), out errors);
// No parsing errors

parser.Parse(new StringReader("CREATE PROCEDURE Proc1 AS DECLARE @ProcName SYSNAME = 'Proc2' EXEC @ProcName;2"), out errors);
// Parsing error! "Incorrect syntax near ;." This should parse succesfully

Did this occur in prior versions? If not - which version(s) did it work in?
Not work in all prior versions.

(DacFx/SqlPackage/SSMS/Azure Data Studio)

Hi @Turyansky, thank you for submitting this issue. I couldn't find documentation of variable versioning in SQL Server. Can you please clarify the issue? What does ";2" mean in this case?

AFAICT it is equivalent to

CREATE PROCEDURE Proc1 AS
BEGIN
	DECLARE @ProcName SYSNAME = 'Proc2'
	EXEC @ProcName;2
END

The ";2" is the "procedure group" functionality, see ";number" at https://learn.microsoft.com/en-us/sql/t-sql/language-elements/execute-transact-sql?view=sql-server-ver16