|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:36 AM
Points: 2,522,
Visits: 3,616
|
|
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
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 3:36 AM
Points: 721,
Visits: 1,330
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 1:19 AM
Points: 2,473,
Visits: 2,131
|
|
Nice and easy question to end the week on - thanks
------------------------------- Posting Data Etiquette - Jeff Moden 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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 1,074,
Visits: 1,076
|
|
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? 
~ demonfox ___________________________________________________________________ Wondering what I would do next , when I am done with this one
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: 2 days ago @ 9:56 AM
Points: 443,
Visits: 1,191
|
|
ah ... this was soo easy, i just selected the answer in one click.... but selected the wrong one. (interesting read, so far)
ww; Raghu -- There are only 10 types of people in the world, those who understand binary, and those who don't.
Note: (as of now) only.. 1 and 4 applies (i am on my way...)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 6:46 AM
Points: 1,074,
Visits: 1,130
|
|
kapil_kk (3/15/2013)
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.
[code="sql"] 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),'*')
Kapil, you need to SET ANSI_WARNINGS OFF. Look at below two examples. Example 1 execute successfully but example 2 give an error.
---- Example 1 SET ANSI_WARNINGS OFF SET ARITHABORT OFF GO
select isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*') GO
SET ARITHABORT ON SET ANSI_WARNINGS ON
---- Example 2 SET ANSI_WARNINGS ON GO
select isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*') GO
Keep Learning - Keep Growing !!! http://growwithsql.blogspot.in
Thanks Vinay Kumar
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 1:49 AM
Points: 3,123,
Visits: 4,310
|
|
Nice, simple question to end the week, thanks Eli
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 4:08 AM
Points: 52,
Visits: 150
|
|
Nice question, thanks. It made me think - I better rest now ......
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 7:40 PM
Points: 1,059,
Visits: 1,150
|
|
Danny Ocean (3/15/2013)
kapil_kk (3/15/2013)
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.
[code="sql"] 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),'*') Kapil, you need to SET ANSI_WARNINGS OFF. Look at below two examples. Example 1 execute successfully but example 2 give an error. ---- Example 1 SET ANSI_WARNINGS OFF SET ARITHABORT OFF GO select isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*') GO SET ARITHABORT ON SET ANSI_WARNINGS ON ---- Example 2 SET ANSI_WARNINGS ON GO select isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*') GO
Yes, It works....
|
|
|
|