Length

  • Comments posted to this topic are about the item Length

    [font="Times New Roman"]For better assistance in answering your questions
    Click Here[/url][/font]

  • 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..........

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • 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 agree with bitbucket: the question is for nVarchar, not nChar.

    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)

    I am gessing that "datalenght" does not count the two extra bytes, because it is supposed to "returns the number of bytes used to represent any expression", and not the number it takes to store it... Am I right? I don't think it would be useful command, but does a SQL command exists to know the number of bytes that a value would take in the database?

  • Good to see that I am not the only one to claim that the proposed answer is COMPLETELY wrong.

    It was kind of shocking to see that it was wrong when I selected 4 and thought what did I do wrong. Alas, it was just the question that was wrong:-D

    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 am also surprised to see sooooo many people answering 60 on this one because that is clearly wrong.

    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

  • The reference given for the answer is also misunderstood, it seems. MS says,

    Use nvarchar when the sizes of the column data entries are probably going to vary considerably.

    This, I suppose, would mean that when the data length varies considerably, we would have to specify the column length assuming the max. length of any data. And in such case, if those many bytes are going to be reserved for each record in the column, then that's really bad for a good database.

    Since MS is advising us to use nvarchar in such cases, it will definitely not be behaving as above and so there is no question of 60 as the answer.

    Does that make sense?

  • Here the question is asked for nvarchar not for nchar.

    For nvarchar the answer should be 4 and for nchar it's 60...

  • Today I thought "Finally! An easy one!!" and specified 4 only to find out the question wasn't checked properly and I ended up getting it wrong anyway :crazy: It's not the end of the world but it is kinda fail that nobody bothered to at least double check the answer.

    Quickly correct it before any other poor souls stumble across it.

  • 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.

    -----------------
    Gobikannan

  • Here asked for nvarchar.

    For nvarchar the answer should be 4 and for nchar it's 60...

  • The explanation talks about nchar, however the question is about nvarchar.

    In my opinion the explanation is wrong and we should all get 10 extra points.

  • the answer of this question is 4 not 60. i.e. the answer mentioned is wrong. when excutes this query it gives the result 4 in sqlserver 2005

  • the max limit of nvarchar is given 30 but it is not complesory that every variable takes max length

  • Books online reference below.

    nvarchar [ ( n | max ) ]

    Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for nvarchar are national char varying and national character varying.

    ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/81ee5637-ee31-4c4d-96d0-56c26a742354.htm

    Answer should be 6.

    M&M

Viewing 15 posts - 1 through 15 (of 138 total)

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