turn sql string and call into separate function