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: Tuesday, December 1, 2015 6:09 AM Points: 2,891, Visits: 3,889
 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: Sunday, November 22, 2015 11:42 PM Points: 907, Visits: 1,387
 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
 SSCarpal Tunnel Group: General Forum Members Last Login: Yesterday @ 7:40 AM Points: 4,259, Visits: 4,466
 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: Tuesday, October 11, 2016 10:43 AM Points: 1,145, Visits: 1,191
 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
 Hall of Fame Group: General Forum Members Last Login: Monday, November 28, 2016 1:13 AM Points: 3,367, Visits: 3,190
 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
 SSCommitted Group: General Forum Members Last Login: Friday, September 16, 2016 10:22 AM Points: 1,574, Visits: 2,958
 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.
Post #1431424
 Posted Friday, March 15, 2013 4:08 AM
 Ten Centuries Group: General Forum Members Last Login: Thursday, July 23, 2015 2:40 AM Points: 1,242, Visits: 1,549
 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
 SSCertifiable Group: General Forum Members Last Login: 2 days ago @ 9:44 PM Points: 5,356, Visits: 7,064
 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
 SSC Journeyman Group: General Forum Members Last Login: Monday, August 15, 2016 8:15 AM Points: 97, Visits: 379
 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
 SSCrazy Group: General Forum Members Last Login: Tuesday, November 8, 2016 4:31 AM Points: 2,222, Visits: 2,760
 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