Can't use DECLARE @variable in console script

Completed

I've found several similar posts that are 5+ years old with no answers.

I'm connected to a MS SQL Server database. I've set the SQL Dialects to MS SQL Server. I've set the console mode to “Script” but I can't get the following basic SQL to run. I know Datagrip has it's own system for variables, but I have various scripts that use it saved from SSMS that I can't run without rewriting.

DECLARE @id INT = 1;

SELECT * FROM Users WHERE id = @id;
GO
0
7 comments

Hi,

I've set the console mode to “Script” but I can't get the following basic SQL to run.

I've tried running these queries together (by selecting them and clicking Execute), and it works for me. Are you seeing any specific errors when running it? Could you share a screenshot? Also, what version of DataGrip are you using?

0

Using 2025.1.3

Whether I run the whole script or highlight all the statements and run them I get a prompt to enter parameter values

0

Could you additionally share a screenshot of your settings from Database > Query Execution and Database > Query Execution > User Parameters?

0

Please exclude the pattern (?<![@<])@[a-zA-z0-9_]+ for Microsoft SQL Server in the User Parameter. With this setting, DataGrip treats @id as a user parameter and prompts to manually input the parameter value. Let me know if this resolves the issue.

0

That fixed it, thank you very much!

0

Glad it helped, you're welcome!

0

Please sign in to leave a comment.