/build/static/layout/Breadcrumb_cap_w.png

MySQL User-Defined Variables

Does the KACE MySQL reporting support user-defined variables?

I have reports that will use date ranges that will require select users editing the SQL statements. I would like to use user defined variables for the start and end dates of the query so that the dates can be defined once at the top of the SQL but used multiple times as needed in the SQL.

I am starting with:
select
SUBSTRING_INDEX(HD_CATEGORY.NAME, '::', 1) AS 'Category',
count(HD_TICKET.ID) as 'Ticket Count'
from HD_TICKET
left join HD_CATEGORY on HD_CATEGORY_ID = HD_CATEGORY.ID
where date(created) between "2011-03-01" and "2011-03-16"
group by CATEGORY
order by CATEGORY


And would like to do something such as:
SET @start_date = 2011-03-01;
SET @end_date = 2011-03-01;

select
SUBSTRING_INDEX(HD_CATEGORY.NAME, '::', 1) AS 'Category',
count(HD_TICKET.ID) as 'Ticket Count'
from HD_TICKET
left join HD_CATEGORY on HD_CATEGORY_ID = HD_CATEGORY.ID
where date(created) between @start_date and @end_date
group by CATEGORY
order by CATEGORY


In the MySQL Query Browser, the SET commands are viewed as being separate from the SELECT - I can run one or the other but not both. I receive no errors, but also retrieve no data.

Using variables in-line in the SQL defeats the purpose of the variables - to move them to the top of the SQL and allow reuse in case I wish to run a union query.

Thanks!
- Allen

0 Comments   [ + ] Show comments

Answers (1)

Posted by: bostonbound 13 years ago
Purple Belt
0
After some additional digging it appears that variables may not yet be supported...
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ