• ScottPletcher (8/25/2016)


    Rather than literal strings of spaces, I recommend using SPACE(), just for readability:

    /*CREATE FUNCTION ...*/

    SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(@Text)),

    SPACE(33), ' '),

    SPACE(17), ' '),

    SPACE(9), ' '),

    SPACE(5), ' '),

    SPACE(3), ' '),

    SPACE(2), ' '),

    SPACE(2), ' ') AS NewText

    +1

    Excuse me, I need to go re-write some code.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001