Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

ASP.NET with 2.0/3.5, Silverlight 2/3/4, WPF, WCF, nHibernet, Javascript, Jquery, Ajax, C#-2.0/3.0, Sql server 2005/2008, MySql 5.1., RIA WCF Service, Entity Framework.
Browse by Tags · View All
.Net 8
SQL 5
Sql Server 3
T SQL 3
linq 3
ORM 2
ORM 2
Browser 2
Silverlight 2
C# 2

Archive · View All
December 2011 9
January 2012 4
July 2012 3
October 2012 1
September 2012 1
August 2012 1
May 2012 1
April 2012 1
March 2012 1
February 2012 1

What is wrong with IsNumeric()?

May 19 2012 12:00AM by Viral Sarvaiya   

I face very strange thing with IsNumeric() function in sql

select IsNumeric('1234D234')
select IsNumeric('123A123')

Both query have alphanumeric value and both give different answer. very strange.

After a long time spent on google i get solution. We can say or cannot say that there are bug in IsNumeric() function.

IsNumeric() can falsely interpret non-numeric letters and symbols (such as D, E, and £, $), and even tabs (CHAR(9)) as numeric.

With this character, Why IsNumeric() can not give right answer? because D stand for Decimal. that value consider as a decimal value, E stand for exponential and $,£ is stand for currency symbol. so Isnumeric() fail to convert those values which has like D,E,$,£ characters.

so to get around this problem, we can create user define function which find the value is integer/numeric. as below.

CREATE FUNCTION dbo.CheckNumeric
(
  @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)>0
          AND @num NOT LIKE '%-%'
         AND
            (
               ((@pos = LEN(@num)+1)
                     OR @pos = CHARINDEX('.', @num))
               )
         THEN   1
         ELSE
            0
      END
   END
GO

Or

CREATE FUNCTION dbo.CheckInteger
(
@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) <= 1
            AND @num NOT IN ('.', '-', '+', '^')
            AND LEN(@num)>0
            AND @num NOT LIKE '%-%'
         THEN
            1
         ELSE
            0
         END
     END
GO

http://codesimplified.com/2012/05/18/what-is-wrong-with-isnumeric/

Learn From: http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Thanks.

Tags: What is wrong with IsNumeric()?, IsNumeric(), Bug in IsNumeric(), SQL, T-SQL


Viral Sarvaiya
175 · 1% · 279
5
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • I would not say that ISNUMERIC() is doing anything wrong.

    Here's my perspective around this:

    NUMERIC is a superset of integer, decimal, monetary and other float/real values. The ISNUMERIC therefore returns a 1 if the expression being evaluated conforms to any one of these values.

    Now, coming to the problem of checking whether a given value is an integer or not, a CAST or a COVNERT wrapped in a TRY...CATCH block (for eg. if testing for an integer, try CASTing to INT) may also be an approach that can be followed.

    commented on May 19 2012 10:09AM
    Nakul Vachhrajani
    4 · 33% · 10575

Your Comment


Sign Up or Login to post a comment.

"What is wrong with IsNumeric()?" rated 5 out of 5 by 5 readers
What is wrong with IsNumeric()? , 5.0 out of 5 based on 5 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]