I have a simple MySQL query. Something like this:
`SELECT COUNT(*) AS lead_count WHERE leads.campaign_id = '12345' and leads.deleted = 0 AND leads.date_entered BETWEEN '2024-08-01 05:00:00' AND '2024-08-28 04:59:59' ORDER BY lead_count DESC;`
This works fine if I leave it just as is. I then introduced some variables for the start time and end time (just because of how our DB is) and so I changed the variable in the mysql to this:
`SELECT COUNT(*) AS lead_count WHERE leads.campaign_id = '12345' and leads.deleted = 0 AND leads.date_entered BETWEEN {{ dateRange1.value.start + " " + varStartTime.value.trim() }} AND {{ dateRange1.value.end + " " + varEndTime.value.trim() }} ORDER BY lead_count DESC;`
And the above works just fine. Now, I have a scenario where IF the user doesn't want to look at a singular campaign but, they want to look at ALL campaigns, I need to remove the very first where clause which is removing the "leads.campaign_id = '12345 and" string.
So, at first, I created a simple variable so I could change it dynamically. That didn't work and brought back blank data.
`SELECT COUNT(*) AS lead_count WHERE {{ varCampaignIDs }} leads.deleted = 0 AND leads.date_entered BETWEEN '2024-08-01 05:00:00' AND '2024-08-28 04:59:59' ORDER BY lead_count DESC;`
Where, "varCampaignIDs" just = 'leads.campaign_id = '12345' AND'
And that didn't work either. Blank response again.
I then dynamically inserted an "ALL" value in a dropdown I was having the user to choose from. So, I ended up with this sql:
`SELECT COUNT(*) AS lead_count WHERE {{ select1.value = '5555' ? '': "leads.campaign = " + select1.value + " AND "}} leads.deleted = 0 AND leads.date_entered BETWEEN '2024-08-01 05:00:00' AND '2024-08-28 04:59:59' ORDER BY lead_count DESC;`
The above is not working either and brings back errors. No matter what I try (and I have tried plenty of things) it just won't allow me to change the mysql with a variable for some reason but it is fine if I use other variables. Scratching my head on this one. Any thoughts or ideas? Thanks!