You mention querying data from a SQL database. You can use DBXL's QueryDB for this; here are some links to documentation:
http://www.infopathdev.com/files/folders/sql_integration/entry65681.aspx
http://www.infopathdev.com/files/folders/sql_integration/entry65683.aspx
You've tagged this as qRules; can you clarify which qRules command you are using or wish to use?
It sounds like you have a working form and wish to make changes to it. We offer a forms detailing service which you can read about at this link: http://www.qdabra.com/en/consulting/detailingService.aspx