Subtle Line Feed / Carriage Return issue

  • dbuendiab (12/23/2010)


    Anyway, I admit it was a sure-you-lose-question.

    There are other ways to get points.

    The only loss here is your time for what looks like a cut and paste error.

    :w00t:

  • Carlo Romagnano (12/23/2010)


    Some tools (powerbuilder,qlick) replace CR and LF with space, so one line comment

    in the script could alter the command.

    Running the script in sql2000 I get 1,3,4 but in sql2005 + sp I get 1,2,3,4.

    Running script in PowerBuilder I get just a comment

    -- comment 1 print 1 -- comment 2 print 2, etc.

    What about Quick Base or FileMaker?

    I would guess they get the same result.

  • Might as well add me to the list of having the right answer and getting it marked wrong.

    A QotD on a bug that has been fixed for years is a poor QotD



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • stewartc-708166 (12/23/2010)


    par for the course....

    CR was a placemarker character, left over from the old typeset days, which told the typesetter to go to the begining of a line (or the first available space thereafter). It was thus used in conjunction with the NL character which, without it, would cause the cursor to go to the next line, but continue from the same position.

    Just FYI, different Operating systems do it differently anyway.

    I'm pretty sure Unix/Linux doesn't put both CR and LF (Carriage Return and Line Feed) characters at the end of a line in a text file. As I've learned when I open said documents in notepad. Other text editors for Windows (Programmers File Editor as an example) treat the one character (instead of two) text files with no trouble and open them up with formatting intact.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • I got 1,2,3,4 as a result too.

  • SQL 2005 provides the following output:

    What you see...

    -----------------------

    print 1

    -- Comment one

    print 2

    -- Comment two

    print 3

    -- Comment three

    print 4

    is not what you get!

    -----------------------

    1

    2

    3

    4

    Need to correct your answer.

    Raymond Laubert
    Exceptional DBA of 2009 Finalist
    MCT, MCDBA, MCITP:SQL 2005 Admin,
    MCSE, OCP:10g

  • Good question but wrongly framed.

    Oh......I lost a point too. Damn, Bad beginning for a Christmas eve.

    SQL DBA.

  • Ran this under SQL Server 2005 SP3 (9.0.4053) and got following results:

    What you see...

    -----------------------

    print 1

    -- Comment one print 2

    -- Comment two

    print 3

    -- Comment three

    print 4

    is not what you get!

    -----------------------

    1

    2

    3

    4

    Interestingly, in Management Studio the '-- Comment one' and 'print 2' display on separate lines and apparently are parsed that way, but when copied/pasted into this window they are combined on the same line. This could have been a better question, with answers that don't depend on an unpatched old version of SQL Server.

  • Bug must be fixed in 2008:

    What you see...

    -----------------------

    print 1

    -- Comment one

    print 2

    -- Comment two

    print 3

    -- Comment three

    print 4

    is not what you get!

    -----------------------

    1

    2

    3

    4

    Ted Seeber
    I find your secrets in your data.
    http://www.informaitonr.us

  • Only if you've failed in the server patch department- this was fixed SQL Server 2005 SP1

    Ted Seeber
    I find your secrets in your data.
    http://www.informaitonr.us

  • Thanks for the question. It would have been nice to have something a little more current.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I also got 1,2,3,4 so not sure what the question was trying to show - no bug here!

  • the question would have been alright in 2005 when that was an issue

    so the only people to get the question right were people have fully patched sql 2005

  • Just the opposite- If you FAILED to patch your server, you got this quesiton right- and failed to patch it EVER since this was fixed in SP1.

    Still, interesting behavior for the compiler when dealing with line comments. And I'm willing to bet there are MANY other compilers out there, for a variety of languages, that don't recognize CR/LF, CR, AND LF (sorry, I'm old enough to remember Epson printer coding in the late 1970s- I will NEVER see char(10) as NL instead of LF, even though they have the same meaning- new line or line feed) as end of line. And for those who are actually coding compilers, it's a darn good lesson to remember to test for all three as end of line.

    Ted Seeber
    I find your secrets in your data.
    http://www.informaitonr.us

  • What I got out of this question is that it shows there once was a bug in SQL2K, which was corrected with SP updates years ago. I usually walk away with learning something from the questions, but this one feels like a waste of time.

    I have access to a SQL2K, SP4 server with Query Analyzer as well as SQL2K5 9.0.3054 with Management Studio 2005. In both instances I get the following:

    What you see...

    -----------------------

    print 1

    -- Comment one

    print 2

    -- Comment two

    print 3

    -- Comment three

    print 4

    is not what you get!

    -----------------------

    1

    2

    3

    4

Viewing 15 posts - 31 through 45 (of 65 total)

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