Arithmetic 1

  • Comments posted to this topic are about the item Arithmetic 1

    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]

  • Good Question. Back to the basics. +1 to the total.

  • Good Question....

  • Very interesting question. Learnt something new again.

  • The explanation I see is that on answers 1,3,4,5,6 implicit data types conversion happens because of mixing INT and CHAR types.

    On the answer 2, we just try to multiply 2 CHAR, therefore an error is raised up.

    Good question!

  • raulggonzalez (2/29/2012)


    The explanation I see is that on answers 1,3,4,5,6 implicit data types conversion happens because of mixing INT and CHAR types.

    On the answer 2, we just try to multiply 2 CHAR, therefore an error is raised up.

    Good question!

    Yeah, I have to agree, multiplying strings is the cause. It errors before it even tries to implicitly cast the answer to an int.

  • I particularly like the fact that a QOTD was verified by several people before publication.

  • It gives me this error on the 2nd block

    Msg 8117, Level 16, State 1, Line 3

    Operand data type char is invalid for multiply operator.

    I guess E stands for ERROR?

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • This kind of error also is independent from version of sqlserver.

    You can not use - * / operators with chars

  • Yet another question that tells us not to rely on implicit conversion...

  • Carlo Romagnano (2/29/2012)


    This kind of error also is independent from version of sqlserver.

    You can not use - * / operators with chars

    Well, you obviously can - as long as one of the other operators is a numeric type, so that SQL can decide what to attempt to convert the chars to. That's the level of guidance that SQL expects and it seems a decent compromise, rather than just making it so it will attempt a conversion to a non-specified type.

  • Raghavendra Mudugal (2/29/2012)


    It gives me this error on the 2nd block

    Msg 8117, Level 16, State 1, Line 3

    Operand data type char is invalid for multiply operator.

    I guess E stands for ERROR?

    You wouldn't have had to guess if you read the statement after the SQL:

    For simplity in creating the possible answers each answer is composed of a comma separated list and if execution of one of the above generates an error the letter E will be included in the list.

  • I would thing the devil were in the details.

    In fact a lot of the questions would fail if not for the fact that the numeric in the question is in fact a numeric.

    The trap, if we can call it that, is that no none-character values were there to coax the cast. If #2 had been constructed like the others, thus having the number '4' as a number in stead of a string, the statement would have done the cast and no error would have followed.

    Inserting a character i e.g. #4 would of course cause that one to fail as well.

  • I'm pretty sure SQL ill not multiply chars '1' * '4' it demands at least one numeric type to decide for the result type.

    Yes! Implicit convertion is evil.

    Even worst when converting dates and using fancy collations and no US-en.

  • good question!!!

    thanks Ron!!!


    [font="Times New Roman"]rfr.ferrari[/font]
    DBA - SQL Server 2008
    MCITP | MCTS

    remember is live or suffer twice!
    the period you fastest growing is the most difficult period of your life!

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

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