InfoPath is designed to be codeless although one can certainly write code into it. However, you can accomplish many tasks without writing code by using the qRules tool and the DBXL tool which can be run with SQL. May I suggest you download the trial versions of these tools and see if they can help you accomplish your goal?
Let me know how you make out.