March 14, 2013 at 8:08 pm
Comments posted to this topic are about the item Casting question
March 14, 2013 at 8:09 pm
March 14, 2013 at 10:19 pm
cheeky ...
didn't occur a doubt on the 0 😛
though I had a doubt over
select isnull ( convert (char(3),1.0/9) ,'*')
-- or
select isnull ( convert (char(3),1/9.0) ,'*')
and it clears out as it does throws an error
Msg 8115, Level 16, State 5, Line 1
Arithmetic overflow error converting numeric to data type varchar.
When Implicit conversion occurs , it gives out the output with default precision of 18,6..
so 1.0/9 is 0.111111..
Select select isnull ( convert (char(8),1.0/9) ,'*')
anything less than 8 would have the arithmetic overflow error for this scenario 😀
Nice question , though ...
Thanks for the question ..
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
March 14, 2013 at 10:38 pm
Nice question..
--
Dineshbabu
Desire to learn new things..
March 14, 2013 at 10:39 pm
Easy one for me. Thanks!
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
March 14, 2013 at 11:24 pm
demonfox (3/14/2013)
cheeky ...didn't occur a doubt on the 0 😛
though I had a doubt over
select isnull ( convert (char(3),1.0/9) ,'*')
-- or
select isnull ( convert (char(3),1/9.0) ,'*')
and it clears out as it does throws an error
Msg 8115, Level 16, State 5, Line 1
Arithmetic overflow error converting numeric to data type varchar.
thanks for the explanation 🙂
When Implicit conversion occurs , it gives out the output with default precision of 18,6..
so 1.0/9 is 0.111111..
Select select isnull ( convert (char(8),1.0/9) ,'*')
anything less than 8 would have the arithmetic overflow error for this scenario 😀
Nice question , though ...
Thanks for the question ..
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 15, 2013 at 12:02 am
Really a nice and good question.
one more thing apart from this question. if you set ARITHABORT OFF and then execute below code, it will give output as "*" due to insufficient char length. and if you set char length more than 7, it will give "0.111111".
It denotes that we need to provide an insufficient length whenever we convert values in char or varchar.
SET ARITHABORT OFF
select isnull ( convert (char(3),1.0/9) ,'*')
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
March 15, 2013 at 12:29 am
Danny Ocean (3/15/2013)
Really a nice and good question.one more thing apart from this question. if you set ARITHABORT OFF and then execute below code, it will give output as "*" due to insufficient char length. and if you set char length more than 7, it will give "0.111111".
It denotes that we need to provide an insufficient length whenever we convert values in char or varchar.
SET ARITHABORT OFF
select isnull ( convert (char(3),1.0/9) ,'*')
Thanks Vinay for this... 🙂
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 15, 2013 at 12:37 am
Your Welcome Kapil 🙂
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
March 15, 2013 at 12:38 am
Danny Ocean (3/15/2013)
Really a nice and good question.one more thing apart from this question. if you set ARITHABORT OFF and then execute below code, it will give output as "*" due to insufficient char length. and if you set char length more than 7, it will give "0.111111".
It denotes that we need to provide an insufficient length whenever we convert values in char or varchar.
SET ARITHABORT OFF
select isnull ( convert (char(3),1.0/9) ,'*')
Vinay, I tried with ARITHABORT OFF but still I am getting same error "Arithmetic overflow error converting numeric to data type varchar."
set arithabort off
select ISNULL(CONVERT(char(3),1.0/9),'*')
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 15, 2013 at 1:32 am
Good question but the correct answer is "0 " (with 2 trailing spaces), not "0".#
Edit: Add example:
SELECT REPLACE(ISNULL ( CONVERT (char(3),1/9),'*'),' ','<Space>') AS Ret
0<Space><Space>
Best Regards,
Chris Büttner
March 15, 2013 at 1:53 am
Nice and easy question to end the week on - thanks
-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
March 15, 2013 at 1:54 am
okbangas (3/15/2013)
Really easy question, but the explanation puzzles me. As far as I can see it is no implicit conversion, just a pure integer division.
+1
0.111111 being counted as 0 , is a round off to integer ..
will that be implicit conversion OP had in mind,0.11111-float to 0 - int? :unsure:
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
March 15, 2013 at 2:21 am
okbangas (3/15/2013)
Really easy question, but the explanation puzzles me. As far as I can see it is no implicit conversion, just a pure integer division.
+1
Viewing 15 posts - 1 through 15 (of 34 total)
You must be logged in to reply to this topic. Login to reply