I have the following MySQL Query.
DECLARE RecCount Int Default 0;
SET RecCount=(select count(*) from tables where WaiterID=1 and date(TDate)=date(now()));
When I execute it, I get the following error:
Error Code: 1193. Unknown system variable 'RecCount'
So, I googled 'declaring variables in MySQL.' It appears that everyone uses DECLARE
:
I don't understand why my query doesn't execute.
I'm using MYSQL WORKBENCH 6.0 CE and I eventually want to execute this query in PHP.
EDIT:
I have used the default as 0. If I remove the default 0, AND change the query to what I've written below, it executes. But it still doesn't save the result like it should!
SET RecCount=(select count(*) from tables where WaiterID=1 and date(TDate)=date(now()));
SELECT RecCount;
If you use control statements you have to use them in a function or procedure.
MySQL supports the IF, CASE, ITERATE, LEAVE LOOP, WHILE, and REPEAT constructs for flow control within stored programs.
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With