February 28, 2012 at 8:41 pm
Comments posted to this topic are about the item Arithmetic 1
February 28, 2012 at 8:43 pm
Good Question. Back to the basics. +1 to the total.
February 28, 2012 at 10:11 pm
Good Question....
February 29, 2012 at 12:38 am
Very interesting question. Learnt something new again.
February 29, 2012 at 1:37 am
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!
February 29, 2012 at 1:41 am
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.
February 29, 2012 at 1:48 am
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.
February 29, 2012 at 1:54 am
This kind of error also is independent from version of sqlserver.
You can not use - * / operators with chars
February 29, 2012 at 2:34 am
Yet another question that tells us not to rely on implicit conversion...
February 29, 2012 at 3:09 am
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.
February 29, 2012 at 3:24 am
Raghavendra Mudugal (2/29/2012)
It gives me this error on the 2nd blockMsg 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.
February 29, 2012 at 3:59 am
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.
February 29, 2012 at 4:17 am
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.
February 29, 2012 at 4:28 am
good question!!!
thanks Ron!!!
Viewing 15 posts - 1 through 15 (of 35 total)
You must be logged in to reply to this topic. Login to reply