more robust elevation in sql