Fixed bug with transaction completion into SQL and implemented transaction query