Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:02+00:00 2026-05-27T10:59:02+00:00

MySQL Gurus, I’m converting some reports from a MSSQL database for usage on a

  • 0

MySQL Gurus,

I’m converting some reports from a MSSQL database for usage on a MySQL Database, and don’t seem to understand how the DECLARE works in MySQL. Below is the SQL code for the report, as works in MSSQL. I read that DECLARE can only be use in a nested function, I belive, but that just does not sound right to me.

Current Report SQL: (I parse & replace the values of Current & Pending from my app 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 > 0 AND SitePendingLocation <> SiteCurrentLocation) AND
(SiteCurrentLocation = @Current OR @Current = 0) AND
(SitePendingLocation = @Pending OR @Current = 0)

Any insight?

Thanks – Andrew

EDIT

Working, converted script – that it may help others:

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 > 0 AND SitePendingLocation <> SiteCurrentLocation) AND
(SiteCurrentLocation = @Current OR @Current = 0) AND
(SitePendingLocation = @Pending OR @Current = 0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:59:03+00:00Added an answer on May 27, 2026 at 10:59 am

    You can either use SET by itself (no DECLARE) or replace @ with _ or similar (or even no prefix).

    I generally prefix mine with _

    See What's wrong with this MySQL statement: DECLARE @ID INT for a similar question

    As regards your other comment, it’s IFNULL in MySql – See http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_ifnull

    It’s always the little things… 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for some help and advice please from Super Guru MySQL/PHP pros who can
MySQL ResultSets are by default retrieved completely from the server before any work can
mysql> select count(*) from table where relation_title='xxxxxxxxx'; +----------+ | count(*) | +----------+ | 1291958
I'm far from being a mysql guru, so need to know if there's a
MySQL 4.0 doesn't have information_schema and 'show table status from db ' only gives
MySQL questions are some of my favorites on StackOverflow. Unfortunately, things like this: SELECT
MySQL saves all changes to the database in a binary file called binary log.
MySQL double while loop in php: $geta=mysql_query(SELECT id FROM table1 WHERE id<50); while($row=mysql_fetch_array($geta)){ while($row2=mysql_fetch_array($geta)){
I have a system which will return all users from the database and order
Not having much luck getting help from any of you Spring gurus on here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.