Declaring mysql variables inside a heidisql query tab
Asked Answered
R

2

6

I have declared a variable in a heidisql tab like this

DECLARE total_count INT DEFAULT 0;
SET total_count = 10;
select total_count;

but i get this error

/* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE total_count INT DEFAULT 0' at line 1 / / Affected rows: 0 Found rows: 0 Warnings: 0 Duration for 0 of 3 queries: 0.000 sec. */

Should i be declaring ,setting and using the variable like i have done or must i wrap everything inside a stored procedure or a function?.

Ruffin answered 9/10, 2014 at 7:59 Comment(2)
I see you are using dummy column. If you declare you do not need set. Either way works. Then check here sqlfiddle.com/#!2/6b97db/11Roselane
The declare part needs to be dropped since you are using @ sqlfiddle.com/#!2/6b97db/16Ruffin
D
8

Try this:

SET @total_count := 10;
select @total_count;
Dameron answered 9/10, 2014 at 12:9 Comment(1)
The colon isn't necessary. You can do SET @total_count = 10;Marlinmarline
D
2

Dropping the semicolons worked for me, in version 8.2.0, alas with MS SQL 2008

DECLARE @total_count INT
SET @total_count = 10
SELECT total_count
Dombrowski answered 26/1, 2016 at 2:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.