Sql Server While Loop In Select Statement Where Condition