title: MySQL DECLARE Syntax (Converting from MSSQL)
body: <p>MySQL Gurus,</p>
  
  <p>I'm  converting some reports from a MSSQL database for usage on a MySQL Database, and don't seem to understand how the <code>DECLARE</code> works in MySQL.  Below is the SQL code for the report, as works in MSSQL.  I read that <code>DECLARE</code> can only be use in a nested function, I belive, but that just does not sound right to me.</p>
  
  <p>Current Report SQL:  (I parse &amp; replace the values of Current &amp; Pending from my app code)</p>
  
  <pre><code>DECLARE @Current int;
  DECLARE @Pending int;
  
  SET @Current = [1];
  SET @Pending = [3];
  
  Select Ticket.TIcketID,
  ISNULL((Select LocationName from Location where LocationID = Ticket.SiteCurrentLocation), 'Invalid Location') as [Current Location],
  ISNULL((Select LocationName from Location where LocationID = Ticket.SitePendingLocation), 'Invalid Location') as [Pending Location]
  from Ticket
  
  where 
  (SitePendingLocation &gt; 0 AND SitePendingLocation &lt;&gt; SiteCurrentLocation) AND
  (SiteCurrentLocation = @Current OR @Current = 0) AND
  (SitePendingLocation = @Pending OR @Current = 0)
  </code></pre>
  
  <p>Any insight?</p>
  
  <p>Thanks - Andrew</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Working, converted script - that it may help others:</p>
  
  <pre><code>SET @Current = '1';
  SET @Pending = '1';
  
  Select Ticket.TIcketID,
  IFNULL((Select LocationName from Location where LocationID = Ticket.SiteCurrentLocation), 'Invalid Location') as `Current Location`,
  IFNULL((Select LocationName from Location where LocationID = Ticket.SitePendingLocation), 'Invalid Location') as `Pending Location`
  from Ticket
  
  where 
  (SitePendingLocation &gt; 0 AND SitePendingLocation &lt;&gt; SiteCurrentLocation) AND
  (SiteCurrentLocation = @Current OR @Current = 0) AND
  (SitePendingLocation = @Pending OR @Current = 0)
  </code></pre>