Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL DECLARE Syntax (Converting from MSSQL)
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload