Link to home
Start Free TrialLog in
Avatar of kingjely
kingjelyFlag for Australia

asked on

Mysql DECLARE variable

Hi guys,
I want to assign a value to a field

I have done this by

declare totalreferences Int default 0;
select count(transref)
INTO totalreferences
from history
WHERE storenumber = 2 and
Brandnumber = 2

I get,
> syntax error on line 1 near, 'declare totalreferences Int default 0'

If I run the query with out the first line, I get
>Error, 'undeclared variable totalreferences'


What i think Im doing -
declaring totalreferences as an int with a default of 0;
then
selecting the count(transref) , INTO totalreferences
from history
WHERE storenumber = 2 and
Brandnumber = 2



1) can i only use DECLARE inside stored procedure.
2) can someone give me an example using maybe @totalreference if this is what i need

THanks for any help
ASKER CERTIFIED SOLUTION
Avatar of rjdown
rjdown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kingjely

ASKER

Hi guys thanks,
Rj, yea i think what im after is learning how to use variables. cool thanks !

Thanks Chris, for trying.
and Deis. i will have a look thanks !