Changing to SQL to help Query issue