Length

  • I thought I was finally going to find that I had the correct answer, only to find out I did not. I answered the question based on NVARCHAR. That sucks. :crying:

  • It is sad If you answer correctly, but it says "wrong answer" 🙁

    Correct the question (or the answers)

  • Gobikannan (4/7/2011)


    I have answered 4 with out any doubt. But I was shocking to see that it was wrong. When I entered in to the forum I realized that I was not an odd one.

    Same here

  • ARGH!

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • I thought I learned something, but when I ran the script, I found that my original answer was correct.

  • yet another one who thought GREAT, a really simple one! to find that we must read minds to know what the real question is.

    Steve Jimmo
    Sr DBA
    “If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan

  • If it was the nChar then length would be 60 othere wise it would take double the size of the character stored in the variable.


    Warm Regards,

    Jignesh Mehta

  • Yeah I was already formulating my response about a nice easy one for a friday especially after yesterday's challenging question and even more challenging discussion. Well the question really was simple and I am sure that Steve will fix it as usual. 😀

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • The question refer to nvarchar(30) and not nchar(30)

    So:

    declare @a nvarchar(30)

    set @a='aa'

    select datalength(@a)

    The answer is 4

    declare @a nchar(30)

    set @a='aa'

    select datalength(@a)

    The answer is 60

    Georges

  • tilew (4/7/2011)


    What I don't understand, is why SQL told me that the lenght is 4, but microsoft says "the storage size, in bytes, is two times the number of characters entered + 2 bytes. " So, it should be (2 caracters * 2) + 2, that would make 6 bytes... (But there were no "6" bytes answer, so I answered 4)-D

    That was my exact reasoning. If there was an option to select 6 as the answer, I would have "earned" my incorrect answer.

  • Where is the quality control on this forum for verifying correct answers?

  • UMG Developer (4/7/2011)


    Argh! How does something this simple and wrong make it through. Did nobody actually run the code prior to posting the question? :w00t:

    Steve, oh Steve, Cleanup on isle 42.

    I think you mean "Cleanup on [a]isle 2" -- minor spelling correction, and the aisle is a char. :w00t:

    I hope I get my points!

    Happy Friday,

    webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • webrunner (4/8/2011)


    UMG Developer (4/7/2011)


    Argh! How does something this simple and wrong make it through. Did nobody actually run the code prior to posting the question? :w00t:

    Steve, oh Steve, Cleanup on isle 42.

    I think you mean "Cleanup on [a]isle 2" -- minor spelling correction, and the aisle is a char. :w00t:

    I hope I get my points!

    Happy Friday,

    webrunner

    Maybe island 42 needs to be cleaned? 😀

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

  • bitbucket-25253 (4/7/2011)


    Here we go again .... the answer is based on

    NCHAR(n) and based on that the supposed answer is correct

    However (Question text set to Bold and character size altered by this poster)

    the question declare @a nvarchar(30)

    set @a='aa'

    select datalength(@a)

    So the answer does NOT match the question..........

    You are correct. In the question the data type was given as NVARCHAR and not NCHAR. Hence the answer is 4.

  • Guys, I think we all know that the question as originally posted is FUBAR. We know Steve will fix it and points returned. Let's all calm down and wait for Steve to log in.

Viewing 15 posts - 46 through 60 (of 138 total)

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