# "Sorry, An error has occurred" when changing a badge sql trigger to "When a user is edited or created"

**URL:** <https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061>\
**Category:** Bug\
**Created:** [21. Mai 2015 um 07:46 UTC](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061 "2015-05-21T07:46:32Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![db0](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/db0/32/116141_2.png) [@db0](https://meta.discourse.org/u/db0)\
**Post date:** [21. Mai 2015 um 10:13 UTC](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061/8 "2015-05-21T10:13:40Z")

</div>

OK so I have this query:

```
SELECT cf.user_id user_id, cf.updated_at granted_at
FROM user_custom_fields cf
WHERE cf.name like 'user_field_1' AND
LENGTH(cf.value) > 1

```

would it work if I modify it to:

```
SELECT cf.user_id user_id u.id, cf.updated_at granted_at
FROM user_custom_fields cf u
WHERE cf.name like 'user_field_1'
AND (
  u.id IN (:user_ids)
  OR :backfill
)
AND LENGTH(cf.value) > 1

```

?

(Sorry I’m not very good with SQL)

---

_[View the full topic](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061)._
