Added sql for rules