While Loop In Case Statement Sql Server