Fixed sql generation for filters.