﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Mark Horninger  / Conversion Fun / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 06:57:59 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>Yeap, I got it!</description><pubDate>Sat, 21 Nov 2009 02:14:39 GMT</pubDate><dc:creator>Bhavesh_Patel</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>"Conversion failed when converting the varchar value '0,.0' to data type int."No SQL product that I could find returned "error converting to a numeric" when trying to convert a varchar value to Int.Why make the correct answer wrong?Are you practicing up to write certification exam questions where the least wrong answer is the right one?</description><pubDate>Wed, 12 Aug 2009 12:09:39 GMT</pubDate><dc:creator>SanDroid</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>ISNUMERIC() checks whether the input is valid numeric data, that also includes money data type, thats why it used to return 1 for isnumeric('0,.0') cause its a valid money type. On the other hand integer data type is limited to numbers only...</description><pubDate>Tue, 11 Aug 2009 01:13:53 GMT</pubDate><dc:creator>Darpan Sarin</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>That is actually a good question and unfortunately I have no idea :(</description><pubDate>Tue, 11 Aug 2009 00:09:56 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote][b]Christian Buettner (8/10/2009)[/b][hr]Hi Kevin,I think that is not true.Try [code]select isnumeric('$$')[/code] for example.It will evaluate to false, although this character ($) was no issue in your previous example.The reason why your example is returning true, is probably the fact that it can be cast to (small)money.[/quote]My mistake. Thanks for pointing this out. I always thought this function just didn't work properly. Now I see I just didn't understand it's purpose. Any idea why Microsoft didn't implement ISMONEY() ISINT() or ISFLOAT()? ISNUMERIC() seems almost useless for testing before an insert.</description><pubDate>Mon, 10 Aug 2009 10:18:11 GMT</pubDate><dc:creator>kevin.l.williams</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote]Try finding an example that is not convertible to a numeric datatype but that returns true in this function.[/quote]That's impossible :P as per the definition of the function, ISNUMERIC only returns true if the input is convertible to one of the numeric data types.</description><pubDate>Mon, 10 Aug 2009 05:24:32 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote][b]kevin.l.williams (8/7/2009)[/b][hr]isnumeric is just evaluating valid characters. This will produce 1 also[code]select isnumeric('-$,')[/code][/quote]Hi Kevin,I think that is not true.Try [code]select isnumeric('$$')[/code] for example.It will evaluate to false, although this character ($) was no issue in your previous example.The reason why your example is returning true, is probably the fact that it can be cast to (small)money.Try finding an example that is not convertible to a numeric datatype but that returns true in this function.</description><pubDate>Mon, 10 Aug 2009 00:59:29 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>I encountered this issue a couple of month ago and i solved it with the following udf from ASPFAQ.com [url=http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html][/url][code]CREATE FUNCTION dbo.isReallyNumeric  (      @num VARCHAR(64)  )  RETURNS BIT  BEGIN      IF LEFT(@num, 1) = '-'          SET @num = SUBSTRING(@num, 2, LEN(@num))       DECLARE @pos TINYINT       SET @pos = 1 + LEN(@num) - CHARINDEX('.', REVERSE(@num))       RETURN CASE      WHEN PATINDEX('%[^0-9.-]%', @num) = 0          AND @num NOT IN ('.', '-', '+', '^')         AND LEN(@num)&gt;0          AND @num NOT LIKE '%-%'         AND          (              ((@pos = LEN(@num)+1)              OR @pos = CHARINDEX('.', @num))          )      THEN          1      ELSE      0      END  END  GO   CREATE FUNCTION dbo.isReallyInteger  (      @num VARCHAR(64)  )  RETURNS BIT  BEGIN      IF LEFT(@num, 1) = '-'          SET @num = SUBSTRING(@num, 2, LEN(@num))       RETURN CASE      WHEN PATINDEX('%[^0-9-]%', @num) = 0          AND CHARINDEX('-', @num) &lt;= 1          AND @num NOT IN ('.', '-', '+', '^')         AND LEN(@num)&gt;0          AND @num NOT LIKE '%-%'     THEN          1      ELSE          0      END  END  [/code]</description><pubDate>Sat, 08 Aug 2009 09:12:53 GMT</pubDate><dc:creator>hakan.winther</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>I'd like to seee the explanation expanded to explain that [code]select convert(money,'0,.0')[/code] would work, and that is why isNumeric is returning true (i.e. that isnumeric is ignoring the comma because that's what convert does for money).Try: [code]select convert(money,'0,,,0,.0,,,0')[/code]</description><pubDate>Fri, 07 Aug 2009 11:47:51 GMT</pubDate><dc:creator>john.moreno</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote][b]ronmoses (8/7/2009)[/b][hr]Dang it, I knew that was the answer and didn't pick it.  That seemed like the obvious "otherwise, why would I ask the question?" answer.  But no, I had to go and [i]think[/i] about it.  Stupid me. :-)[/quote]Ditto :-).  That said, I would love to hear from the people who thought the answer for a CONVERT(int, {anything}) would be either 0.0 or 0,.0!</description><pubDate>Fri, 07 Aug 2009 10:17:00 GMT</pubDate><dc:creator>Michael Poppers</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>isnumeric is just evaluating valid characters. This will produce 1 also[code]select isnumeric('-$,')[/code]</description><pubDate>Fri, 07 Aug 2009 10:07:03 GMT</pubDate><dc:creator>kevin.l.williams</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>It's just the way that SQL Server deals with Monetary data. It's always got four trailing spaces for decimals, and the decimal symbol (".") is interpreted as being the symbol to indicate that you're dealing with the decimal part of the Money value, while the comma (",") is treated as being part of the non-decimal part.EG: 1,000 is the same as 1000, while 1.000 is the same as 1, and 1,000.1 is the same as 1000.1</description><pubDate>Fri, 07 Aug 2009 09:19:00 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote][b]Christian Buettner (8/7/2009)[/b][hr]If I am not totally wrong, the behaviour is not due to IsNumeric itself, but to the fact that you can cast this value to money or smallmoney.Try this:[code]SET NOCOUNT ONSELECT CONVERT(money ,'1,0.2') A, CONVERT(money ,'1.0,2') B, CONVERT(money ,'1,100,00.2') C[/code][quote][font="Courier New"]A.......B......C..........10.2000	1.0200	110000.2000[/font][/quote]Now dont ask me why...[/quote]Very interesting.  Never thought or tried it or say never came across this kind of issue. Not to you Chris, but to some one else who could give better explanation.My question - Why ?</description><pubDate>Fri, 07 Aug 2009 08:38:44 GMT</pubDate><dc:creator>SanjayAttray</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>I agree with the above post, integer is very specific, in fact forget the odd character, even [code]select convert(int,'0.0')[/code] will not work.   [code]select convert(decimal(2,1),'0,.0')[/code] will give the error that was supplied as one of the answers to the question.Interestingly (or not, it is Friday lunch time), money to int will work no worries, rounding to the nearest int, so [code]select convert(int,convert(money,'0,.0'))[/code] will work fine if you're worried about isnumeric letting you down!  :hehe:</description><pubDate>Fri, 07 Aug 2009 07:10:53 GMT</pubDate><dc:creator>Rob Goddard</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>Essentially, the reason why it doesn't work is because an integer is a subset of the numeric datatypes, and not vice-versa. Things which are numeric are not necessarily integers, while all integers are numeric.</description><pubDate>Fri, 07 Aug 2009 06:30:43 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>I don't believe that isnumeric looks at the string as a whole, but as the individual characters in the string.  I think it's a rather broad assertion that the string [b][i][u]COULD[/u][/i][/b] be converted to a number of some fashion (integer, real, money, etc.).</description><pubDate>Fri, 07 Aug 2009 06:28:58 GMT</pubDate><dc:creator>Aaron N. Cutshall</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>Dang it, I knew that was the answer and didn't pick it.  That seemed like the obvious "otherwise, why would I ask the question?" answer.  But no, I had to go and [i]think[/i] about it.  Stupid me. :-)</description><pubDate>Fri, 07 Aug 2009 05:50:42 GMT</pubDate><dc:creator>ronmoses</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>If I am not totally wrong, the behaviour is not due to IsNumeric itself, but to the fact that you can cast this value to money or smallmoney.Try this:[code]SET NOCOUNT ONSELECT CONVERT(money ,'1,0.2') A, CONVERT(money ,'1.0,2') B, CONVERT(money ,'1,100,00.2') C[/code][quote][font="Courier New"]A.......B......C..........10.2000	1.0200	110000.2000[/font][/quote]Now dont ask me why...</description><pubDate>Fri, 07 Aug 2009 05:47:56 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>[quote][b]srikanth_pallerla (8/7/2009)[/b][hr]why isnumeric gives true when the content contains ','. May be question seems simple but i am new to sql server.[/quote]As per the Books Online page (http://msdn.microsoft.com/en-us/library/ms186272.aspx):"ISNUMERIC returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0."Valid numeric data types include things like Money data types - "ISNUMERIC returns 1 for some characters that are not numbers, such as plus (+), minus (-), and valid currency symbols such as the dollar sign ($). For a complete list of currency symbols, see  Using Monetary Data."Integer is a pretty specific data type. It won't accept things that are considered Numeric in some cases. If you need the ability to detect whether something is an Integer, I'd suggest writing your own UDF. There's many different ways to do it. One thing you can do is to cast the value to a VARCHAR data type, then loop through every character, and see if every character evaluates to an ASCII value between 48 and 57 (numbers 0-9); if any don't,then you'll know that it's not an Integer.</description><pubDate>Fri, 07 Aug 2009 05:37:42 GMT</pubDate><dc:creator>kramaswamy</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>I suspect this is due to the way it handles foreign numbers. When I work with countries using format '0,0' I want it to treat it as numeric based on the server regional settings. Unfortunately, it is more likely that isnumeric() is taking naughty shortcuts and replacing certain characters like the comma - regardless of server settings - whereas convert() is not.</description><pubDate>Fri, 07 Aug 2009 04:42:58 GMT</pubDate><dc:creator>Todd Heidesch</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>why isnumeric gives true when the content contains ','. May be question seems simple but i am new to sql server.</description><pubDate>Fri, 07 Aug 2009 04:37:19 GMT</pubDate><dc:creator>srikanth_pallerla-1082904</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>just 3 days back i had a similar issue with isnumeric. If this QOTD had come then it would have been helpful.</description><pubDate>Fri, 07 Aug 2009 04:28:13 GMT</pubDate><dc:creator>ChiragNS</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>..And answer is in the subject itself...................</description><pubDate>Fri, 07 Aug 2009 02:54:07 GMT</pubDate><dc:creator>Joy Smith San</dc:creator></item><item><title>RE: Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>But aren't you trying to convert it to an integer in the code you supplied rather than a numeric data type?Granted you'll still get the error but if you run the code you'll get the response "Conversion failed when converting the varchar value '0,.0' to data type int" which isn't one of the available answers.</description><pubDate>Fri, 07 Aug 2009 02:00:30 GMT</pubDate><dc:creator>SQLPhil</dc:creator></item><item><title>Conversion Fun</title><link>http://www.sqlservercentral.com/Forums/Topic766707-1375-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/Conversions/66286/"&gt;Conversion Fun&lt;/A&gt;[/B]</description><pubDate>Fri, 07 Aug 2009 00:21:44 GMT</pubDate><dc:creator>SuperDBA-207096</dc:creator></item></channel></rss>