Furthermore,
Embedding SQL within your Flex application would open a significant security hole.
As described above, create a web service and make sure the parameters are cleaned before running the resulting SQL. I have previously created similar geoprocessing services using Python and Model builder.
James.