31

How can I declare a variable for a normal query in MySQL?

e.g.,

declare @myVar date;
set @myVar = something;

select * from someTable where someColumn = @myVar;

I tried and the syntax seems to be wrong...what am I missing?

Zuul
  • 16,217
  • 6
  • 61
  • 88
EOB
  • 2,975
  • 17
  • 43
  • 70

1 Answers1

43

You can declare a session variable in this way :

SET @myvarname := 'value';

or a local variable in this way :

DECLARE my_variable varchar(30)

also:

DECLARE my_variable varchar(30) DEFAULT 'value'
aleroot
  • 71,077
  • 30
  • 176
  • 213