• "t.N BETWEEN 1 AND LEN(@LongString)/@length+1" would list an extra blank row where LEN(@LongString) is a multiple of @length.

    DECLARE @longString varchar(max)

    DECLARE @val varchar(max)

    SET @val = 'abcdefgh'

    SELECT @longString = REPLICATE( @val, 10000 ) -- 80000 char length string

    If you use the string above to split the string into 8000 char strings, you will get 11 rows instead of the expect 10.

    Perhaps

    WHERE N <= CEILING( LEN( @longString ) / CONVERT( numeric(10,1 ), @length ) )

    OR

    WHERE t.N BETWEEN 1 AND CEILING( LEN( @longString ) / CONVERT( numeric(10,1 ), @length ) )

    would be better.