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
Please sign in to leave a comment.
Hi,
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?
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
Could you additionally share a screenshot of your settings from Database > Query Execution and Database > Query Execution > User Parameters?
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.That fixed it, thank you very much!
Glad it helped, you're welcome!