Sometimes I write long queries or a series of queries and save them as an SQL file to run later. Sometimes there are portions of the queries that I end up commenting out so that I can get slightly different results. I am wondering if there is some mechanism I can use directly inside a query/script to control which lines of code are run. Here is a very simple example:
SET @report = 1;
SELECT
c1,
c2,
c3
FROM
table1
##if @report = 1##
WHERE
c1 = true
and c2 = true
GROUP BY
c1
##if @report = 2##
WHERE
c1 = false
and c2 = true
GROUP BY
c1,
c2
;
Additional Note I should have mentioned that most of the time these would be run from MySQL Workbench. Though it could be run from another IDE/tool.
ANSWER Both Drew and Sasha Pachev gave good answers and both would be worth looking at.
- Stored procedures
- Prepared statements