dbeaver / dbeaver

Free universal database tool and SQL client
https://dbeaver.io
Apache License 2.0
39.16k stars 3.38k forks source link

Incorrect syntax near ';'. error on valid DECLARE statement in SQL Server 2019 #32330

Open ray-kudos opened 3 months ago

ray-kudos commented 3 months ago

Description

I tried to run a query below, but encountered an error in DBeaver stating "Incorrect syntax near ';'. " when executed, even though it runs okay in SSMS. BEGIN DECLARE @Error1 INT = CASE WHEN 1 = 1 THEN 1 ELSE 0 END; SELECT @Error1; END image

DBeaver Version

Community Edition Version 24.0.4.202405051837

Operating System

Windows 10 Pro 20H2

Database and driver

  1. MSSQL Server 2019
  2. MS SQL Server / SQL Server

image

Steps to reproduce

  1. Open the master database on MSSQL Server 2019.
  2. Execute scripts below. BEGIN DECLARE @Error1 INT = CASE WHEN 1 = 1 THEN 1 ELSE 0 END; SELECT @Error1; END

Additional context

No response

E1izabeth commented 3 months ago

Thank you for bug report. As a workaround, you can select whole block and press Execute SQL query. image

ray-kudos commented 3 months ago

Thank you for the workaround. It worked for those scripts. However, when I executed the actual scripts below using your workaround, I encountered an "Incorrect syntax near 'GO'." error and if I executed the scripts using Execute SQL Scripts (Alt+X), I received an "Incorrect syntax near ';'." error.

IF OBJECT_ID ( '[dbo].[temp_procedure]', 'P' ) IS NOT NULL DROP PROCEDURE [dbo].[temp_procedure]; GO CREATE PROCEDURE [dbo].[temp_procedure] @ChildDBName NVARCHAR(128), @ParentDBName NVARCHAR(128) AS BEGIN SET NOCOUNT ON; DECLARE @TableSuffix NVARCHAR(128) = CASE WHEN COALESCE(@ParentDBName, '') = '' THEN '' ELSE @ChildDBName END;
END

E1izabeth commented 3 months ago

You can change statement delimiter from ; to GO in preferences image

ray-kudos commented 3 months ago

I have done it but it still shows the same errors. image