• Anyone who knows what happens when a phonenumber is NULL?

    For 2 reasons I would add an extra filter

    1) don't select what you don't need as soon as possible, less records passing your filtering will also speed up your process

    2) working with NULL-values can give surprising effects, so you have to be aware and check ISNULL-function (or as I did here filter them out)

    DECLARE @AllPhones VARCHAR(1000)

    SET @AllPhones = ''

    SELECT @AllPhones = @AllPhones

    + CASE WHEN P.ListThisNumber = 1 THEN P.PhoneNumber ELSE '***********'END

    + ' & '

    FROM dbo.tblPhone P

    WHERE codUser = 1

    AND P.PhoneNumber IS NOT NULL

    SELECT @AllPhonesGO