# SQL Error when Creating Campaign with Condition

**URL:** <https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230>\
**Category:** General Discussion\
**Created:** [January 13, 2016, 1:05pm UTC](https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230 "2016-01-13T13:05:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigbenstock](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@craigbenstock](https://forum.mautic.org/u/craigbenstock)\
**Post date:** [January 13, 2016, 1:05pm UTC](https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230/1 "2016-01-13T13:05:45Z")

</div>

Another day, another problem… Could well be user error on my part again.  
  
  
  
I have a campaign form with a select field consisting of 3 items (product A, product B, product C)  
  
  
  
I want to be able to tag the user with the tags ProductA, ProductB, ProductC respectively depending on what they submit (I also want to email them different emails depending on what they select but I haven’t go that far yet).  
  
  
  
I figured I could create a campaign for this:

- Lead source - is my form  
- Condition - Form field value, limited to my form, using the selection field and with an equals to product A  
- Action - of Adding a Tag ‘ProductA’  
  
  
  
I could then have more conditions and tags for product B, C, etc…  
  
  
  
Unfortunately as soon as I create and publish this campaign I see the following error in the CampaignUpdate process:  
  
  
  
[DoctrineDBALDBALException]  
  
An exception occurred while executing ‘SELECT max(list\_leads.lead\_id) as ma  
  
x\_id, count(distinct(list\_leads.lead\_id)) as lead\_count FROM lead\_lists\_lea  
  
ds list\_leads WHERE (list\_leads.manually\_removed = ?) AND (list\_leads.leadl  
  
ist\_id IN ()) AND (list\_leads.date\_added \<= ‘2016-01-13 12:29:11’) AND (NOT  
  
EXISTS (SELECT null FROM campaign\_leads campaign\_leads WHERE (campaign\_lea  
  
ds.lead\_id = list\_leads.lead\_id) AND (campaign\_leads.manually\_removed = ?)  
  
AND (campaign\_leads.campaign\_id = 6)))’ with params [0, 0]:  
  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
  
n your SQL syntax; check the manual that corresponds to your MySQL server v  
  
ersion for the right syntax to use near ‘)) AND (list\_leads.date\_added \<= ’  
  
2016-01-13 12:29:11’) AND (NOT EXISTS (SELECT ’ at line 1  
  
  
  
[PDOException]  
  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
  
n your SQL syntax; check the manual that corresponds to your MySQL server v  
  
ersion for the right syntax to use near ‘)) AND (list\_leads.date\_added \<= ’  
  
2016-01-13 12:29:11’) AND (NOT EXISTS (SELECT ’ at line 1  
  
  
  
Any thoughts? Do I need to construct my Campaign differently? Is there an alternative way to achieve this?

---

<div class="post-metadata">

**Author:** ![craigbenstock](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@craigbenstock](https://forum.mautic.org/u/craigbenstock)\
**Post date:** [January 13, 2016, 1:05pm UTC](https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230/2 "2016-01-13T13:05:45Z")

</div>

Another day, another problem… Could well be user error on my part again.

I have a campaign form with a select field consisting of 3 items (product A, product B, product C)

I want to be able to tag the user with the tags ProductA, ProductB, ProductC respectively depending on what they submit (I also want to email them different emails depending on what they select but I haven’t go that far yet).

I figured I could create a campaign for this:

- Lead source - is my form
- Condition - Form field value, limited to my form, using the selection field and with an equals to product A
- Action - of Adding a Tag ‘ProductA’

I could then have more conditions and tags for product B, C, etc…

Unfortunately as soon as I create and publish this campaign I see the following error in the CampaignUpdate process:

[DoctrineDBALDBALException]  
An exception occurred while executing ‘SELECT max(list\_leads.lead\_id) as ma  
x\_id, count(distinct(list\_leads.lead\_id)) as lead\_count FROM lead\_lists\_lea  
ds list\_leads WHERE (list\_leads.manually\_removed = ?) AND (list\_leads.leadl  
ist\_id IN ()) AND (list\_leads.date\_added \<= ‘2016-01-13 12:29:11’) AND (NOT  
EXISTS (SELECT null FROM campaign\_leads campaign\_leads WHERE (campaign\_lea  
ds.lead\_id = list\_leads.lead\_id) AND (campaign\_leads.manually\_removed = ?)  
AND (campaign\_leads.campaign\_id = 6)))’ with params [0, 0]:  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
n your SQL syntax; check the manual that corresponds to your MySQL server v  
ersion for the right syntax to use near ‘)) AND (list\_leads.date\_added \<= ’  
2016-01-13 12:29:11’) AND (NOT EXISTS (SELECT ’ at line 1

[PDOException]  
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
n your SQL syntax; check the manual that corresponds to your MySQL server v  
ersion for the right syntax to use near ‘)) AND (list\_leads.date\_added \<= ’  
2016-01-13 12:29:11’) AND (NOT EXISTS (SELECT ’ at line 1

Any thoughts? Do I need to construct my Campaign differently? Is there an alternative way to achieve this?

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 13, 2016, 1:11pm UTC](https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230/3 "2016-01-13T13:11:03Z")

</div>

Seems a lot like the errors from this PR:

[https://github.com/mautic/mautic/pull/1286](https://github.com/mautic/mautic/pull/1286)

So this is a known bug, the fix is above if someone wants to apply the code fix now and it will be fixed in the next release 1.2.4 which is planned for this week if we manage to test 2 times each pull request for this release:

[https://github.com/mautic/mautic/pulls?q=is%3Aopen+is%3Apr+milestone%3A1.2.4](https://github.com/mautic/mautic/pulls?q=is%3Aopen+is%3Apr+milestone%3A1.2.4)

Any help with testing appreciated.

---

<div class="post-metadata">

**Author:** ![craigbenstock](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@craigbenstock](https://forum.mautic.org/u/craigbenstock)\
**Post date:** [January 13, 2016, 1:13pm UTC](https://forum.mautic.org/t/sql-error-when-creating-campaign-with-condition/3230/4 "2016-01-13T13:13:55Z")

</div>

Ah ok great… that does ring a bell now you mention it.
