XF 1.2 Location Field to Country Field


I recently migrated from PHPBB to Xenforo. My location field used to be mandatory during registration in PHPBB which is not possible in Xenforo.

I now have set up a custom field for country with a drop down box which is mandatory during registration.

Is there a way to populate the country field with the location field? Perhaps an SQL query?

The current location field is free text but perhaps there is a way to clean it up to match the standard country field prior to copying over to the Country field.