We have some products that could help you and wouldn't require any code.
DBXL will help you retrieve SQL queries into your InfoPath form and also submit data from an InfoPath form back into SQL: http://www.qdabra.com/en/products/DBXL.aspx
qRules will let you retrieve input parameters easily so that you could use them in your SQL query: http://www.qdabra.com/en/products/qRules_new.aspx
Otherwise, I think you're looking at writing some custom code as there isn't a way to do this out of the box using rules.