Badge not being applied, sql error

Seems like we just got confused that “data explorer” cannot run it like that and it just took quite long to actually hand out the badge.

I may ask here again:
What is the best trigger time for this?