## Casting question

 Author Message Christian Buettner-167247 SSCrazy Group: General Forum Members Points: 2951 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 SSC Eights! Group: General Forum Members Points: 939 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 SSCarpal Tunnel Group: General Forum Members Points: 4520 Visits: 4558 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 Ten Centuries Group: General Forum Members Points: 1221 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 Hall of Fame Group: General Forum Members Points: 3632 Visits: 3237 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 SSCommitted Group: General Forum Members Points: 1698 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 Ten Centuries Group: General Forum Members Points: 1358 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 SSCertifiable Group: General Forum Members Points: 5828 Visits: 7142 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 SSC-Enthusiastic Group: General Forum Members Points: 105 Visits: 379 Nice question, thanks. It made me think - I better rest now ...... ;-) Dave Morris "Measure twice, saw once" kapil_kk SSCrazy Group: General Forum Members Points: 2439 Visits: 2763 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/