split into multiple queries

http://manage.dimagi.com/default.asp?102681#583173