• Wow...

    Two things

    1) Never use Cursors! Looping through a temp table takes less overhead than a Cursor; especially when you are working on a 24/7/365 server where you really need to watch your resources.

    2) Don't write code like this:

    IF @ListThisNumber = 0

    SET @PhoneNumber = '***********'

    SET @AllPhones = @AllPhones + @PhoneNumber + ' & '

    Doing it this way uses one less variable that you have to Declare and Set:

    SELECT @AllPhones = @AllPhones +

    CASE

    WHEN @ListThisNumber = 0 THEN '***********'

    ELSE @PhoneNumber

    END + ' & '

    Imagination is more important than knowledge.

    – Albert Einstein