Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Conversion Fun Expand / Collapse
Author
Message
Posted Friday, August 7, 2009 12:21 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, January 2, 2013 12:15 PM
Points: 1,443, Visits: 711
Comments posted to this topic are about the item Conversion Fun
Post #766707
Posted Friday, August 7, 2009 2:00 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 2:00 AM
Points: 1,442, Visits: 724
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.
Post #766740
Posted Friday, August 7, 2009 2:54 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 7:16 PM
Points: 1,538, Visits: 2,587
..And answer is in the subject itself...................
Post #766759
Posted Friday, August 7, 2009 4:28 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 8:08 AM
Points: 2,365, Visits: 1,846
just 3 days back i had a similar issue with isnumeric. If this QOTD had come then it would have been helpful.

"Keep Trying"
Post #766804
Posted Friday, August 7, 2009 4:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 20, 2013 7:15 AM
Points: 5, Visits: 14
why isnumeric gives true when the content contains ','. May be question seems simple but i am new to sql server.
Post #766812
Posted Friday, August 7, 2009 4:42 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, January 10, 2013 5:45 AM
Points: 54, Visits: 108
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.
Post #766814
Posted Friday, August 7, 2009 5:37 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 8:44 AM
Points: 819, Visits: 1,654
srikanth_pallerla (8/7/2009)
why isnumeric gives true when the content contains ','. May be question seems simple but i am new to sql server.


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.
Post #766846
Posted Friday, August 7, 2009 5:47 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 1:05 AM
Points: 2,842, Visits: 3,875
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:

SET NOCOUNT ON
SELECT CONVERT(money ,'1,0.2') A, CONVERT(money ,'1.0,2') B, CONVERT(money ,'1,100,00.2') C

A.......B......C..........
10.2000 1.0200 110000.2000

Now dont ask me why...


Best Regards,
Chris Büttner
Post #766850
Posted Friday, August 7, 2009 5:50 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 873, Visits: 873
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 think about it. Stupid me.

-----
a haiku...

NULL is not zero
NULL is not an empty string
NULL is the unknown
Post #766851
Posted Friday, August 7, 2009 6:28 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 22, 2014 11:25 AM
Points: 1,127, Visits: 546
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 COULD be converted to a number of some fashion (integer, real, money, etc.).


"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
Post #766871
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse