## Casting question

 Author Message Christian Buettner-167247 SSCrazy Eights Group: General Forum Members Points: 8543 Visits: 3889 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 okbangas SSCertifiable Group: General Forum Members Points: 6775 Visits: 1387 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 Stuart Davies SSChampion Group: General Forum Members Points: 11199 Visits: 4865 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 demonfox Hall of Fame Group: General Forum Members Points: 3657 Visits: 1192 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 Carlo Romagnano SSChampion Group: General Forum Members Points: 12402 Visits: 3517 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 Raghavendra Mudugal SSCertifiable Group: General Forum Members Points: 5552 Visits: 2958 ah ... this was soo easy, i just selected the answer in one click.... but selected the wrong one. (interesting read, so far) ww; Raghu--The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart. Danny Ocean Hall of Fame Group: General Forum Members Points: 3410 Visits: 1549 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 Stewart "Arturius" Campbell SSC-Dedicated Group: General Forum Members Points: 35546 Visits: 7702 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” seatedElephant Old Hand Group: General Forum Members Points: 301 Visits: 382 Nice question, thanks. It made me think - I better rest now ...... ;-) Dave Morris "Measure twice, saw once" kapil_kk SSChampion Group: General Forum Members Points: 10675 Visits: 2778 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/