Fixed sql issue