Fixing bug #3797

This bug cause due to only explode the sql query by 'where' clause.If where clause not in a query then other unwanted parts also got include in the sql query.Please review it and apply.