Counting spaces

  • A variation of this question could be:

    DECLARE @inc int, @dec int;

    SELECT @inc = 1, @dec = 10;

    DECLARE @temp table (StringA varchar(20), StringB varchar(20));

    WHILE @inc <= 10

    BEGIN

    INSERT INTO @temp VALUES ( SPACE(@inc)+'Hello',

    SPACE(@dec)+'Hello');

    SET @inc = @inc + 1;

    SET @dec = @dec - 1;

    END

    select * from @temp

    SELECT COUNT(*) FROM @temp WHERE LEN(StringA)= LEN(StringB);

  • Another lucky guess 🙂

    When you pipe the results out to a text file, you get:

    StringA,StringB

    hello ,hello (one space after first hello)

    hello ,hello (2 spaces after first hello, etc...)

    hello ,hello

    hello ,hello

    hello ,hello

    hello ,hello

    hello ,hello

    hello ,hello

    hello ,hello

    hello ,hello

    with 7 spaces AFTER each second hello, interesting result... why 7 spaces??

    Peter Trast
    Microsoft Certified ...(insert many literal strings here)
    Microsoft Design Architect with Alexander Open Systems

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply