title: Unknown system variable using DECLARE
body: <p>I have the following MySQL Query.</p>
  
  <pre><code>DECLARE RecCount Int Default 0;
  SET RecCount=(select count(*) from tables where WaiterID=1 and date(TDate)=date(now()));
  </code></pre>
  
  <p>When I execute it, I get the following error: </p>
  
  <pre><code>Error Code: 1193. Unknown system variable 'RecCount'
  </code></pre>
  
  <p>So, I googled 'declaring variables in MySQL.' It appears that everyone uses <code>DECLARE</code>:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11505522/mysql-declaring-variables">First Result</a></li>
  <li><a href="https://stackoverflow.com/questions/11505522/mysql-declaring-variables">Second Result</a></li>
  <li><a href="http://dev.mysql.com/doc/refman/5.5/en/declare-local-variable.html" rel="nofollow noreferrer">Third Result</a></li>
  <li><a href="http://dev.mysql.com/doc/refman/5.5/en/declare.html" rel="nofollow noreferrer">Fourth Result</a></li>
  <li><a href="http://dev.mysql.com/doc/refman/5.0/en/user-variables.html" rel="nofollow noreferrer">Fifth Result</a></li>
  </ul>
  
  <p>I don't understand why my query doesn't execute. </p>
  
  <p>I'm using MYSQL WORKBENCH 6.0 CE and I eventually want to execute this query in PHP.</p>
  
  <p><strong>EDIT:</strong><br>
  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!</p>
  
  <pre><code>SET RecCount=(select count(*) from tables where WaiterID=1 and date(TDate)=date(now()));
  SELECT RecCount;
  </code></pre>