fixed sql statement around log