Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Casting question Rate Topic Display Mode Topic Options
Author
 Message
 Posted Friday, March 15, 2013 1:32 AM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 4:48 AM Points: 2,720, Visits: 3,791
 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),'*'),' ','') AS Ret`0 Best Regards, Chris Büttner
Post #1431385
 Posted Friday, March 15, 2013 1:45 AM
 SSC Eights! Group: General Forum Members Last Login: 2 days ago @ 3:09 AM Points: 812, Visits: 1,353
 Really easy question, but the explanation puzzles me. As far as I can see it is no implicit conversion, just a pure integer division. Ole Kristian Velstadbråten Bangås - Virinco - Facebook - TwitterConcatenating Row Values in Transact-SQL
Post #1431388
 Posted Friday, March 15, 2013 1:53 AM
 SSCrazy Group: General Forum Members Last Login: 2 days ago @ 6:10 AM Points: 2,682, Visits: 2,502
 Nice and easy question to end the week on - thanks -------------------------------Posting Data Etiquette - Jeff Moden Smart way to ask a questionThere 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
Post #1431391
 Posted Friday, March 15, 2013 1:54 AM
 Ten Centuries Group: General Forum Members Last Login: Monday, October 14, 2013 7:59 AM Points: 1,119, Visits: 1,149
 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
Post #1431392
 Posted Friday, March 15, 2013 2:21 AM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 9:10 AM Points: 2,221, Visits: 2,116
 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
Post #1431401
 Posted Friday, March 15, 2013 3:31 AM
 Mr or Mrs. 500 Group: General Forum Members Last Login: Yesterday @ 5:27 AM Points: 576, Visits: 1,411
 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...)
Post #1431424
 Posted Friday, March 15, 2013 4:08 AM
 Ten Centuries Group: General Forum Members Last Login: Tuesday, December 03, 2013 2:28 AM Points: 1,239, Visits: 1,541
 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 OFFselect 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 offselect 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 1SET ANSI_WARNINGS OFFSET ARITHABORT OFFGOselect isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*')GOSET ARITHABORT ONSET ANSI_WARNINGS ON---- Example 2SET ANSI_WARNINGS ONGOselect isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*')GO ThanksVinay Kumar-----------------------------------------------------------------Keep Learning - Keep Growing !!!www.GrowWithSql.com
Post #1431434
 Posted Friday, March 15, 2013 4:40 AM
 Hall of Fame Group: General Forum Members Last Login: Today @ 12:51 AM Points: 3,440, Visits: 4,580
 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”
Post #1431442
 Posted Friday, March 15, 2013 4:44 AM
 Valued Member Group: General Forum Members Last Login: Monday, November 18, 2013 8:38 AM Points: 69, Visits: 239
 Nice question, thanks. It made me think - I better rest now ...... Dave Morris "Measure twice, saw once"
Post #1431446
 Posted Friday, March 15, 2013 5:25 AM
 SSCommitted Group: General Forum Members Last Login: 2 days ago @ 8:00 PM Points: 1,725, Visits: 2,017
 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 OFFselect 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 offselect 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 1SET ANSI_WARNINGS OFFSET ARITHABORT OFFGOselect isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*')GOSET ARITHABORT ONSET ANSI_WARNINGS ON---- Example 2SET ANSI_WARNINGS ONGOselect isnull ( convert (char(3),1.0/9) ,'*') ,isnull ( convert (char(8),1.0/9) ,'*')GOYes, It works.... _______________________________________________________________To get quick answer follow this link:http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1431465

 Permissions