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:
And would like to do something such as:
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
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)
Please log in to answer
Posted by:
bostonbound
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.