• Here's another way... same idea, though.

    DROP TABLE #MyHead;

    SELECT TOP (1000)

    ID = ROW_NUMBER() OVER (ORDER BY (SELECT NULL)),

    RandomColor = CASE RandomColor#

    WHEN 1 THEN 'Red'

    WHEN 2 THEN 'Green'

    ELSE 'Yellow'

    END

    INTO #MyHead

    FROM sys.all_columns ac1

    CROSS JOIN sys.all_columns ac2

    CROSS APPLY (SELECT ABS(CHECKSUM(NEWID()))%3) ca (RandomColor#)

    ;

    --===== Show the distribution

    SELECT RandomColor, COUNT(*)

    FROM #MyHead

    GROUP BY RandomColor

    ORDER BY RandomColor

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)