Have you considered using the Velocity Reports plugin ? this should be very achievable. You could produce your report and display this on screen either in smart or web client and offer the user the facility to run SQL queries. https://www.servoyforge.net/projects/velocity-report