fixes #4048 Bad SQL error for non existence content on workflow tasks

Fixed the bad sql error, and pushed the code for review, please check it.