take a look at the simple data environment thread and alter the sql string to your liking

This code may give you a little more flexibility

Hope this helps
Pinkpanther