A number is judged in SQL Server (the. 3 is automatically recognized as 0.3)

Source: Internet
Author: User

SQL Server detects data that is not digital (two methods)

Detection is not a digital type of data, two methods

1. IsNumeric ( expression )

2. PATINDEX ( '%pattern%' , expression )

1. IsNumeric ( expression )

Returns 1 if it is a numeric type, or 0 if not

But IsNumeric is sometimes unreliable, and if you do not allow expression to contain any letters, you will be judged wrong:

Example: IsNumeric (' 23e4 ') returns 1

IsNumeric (' 23d4 ') returns 1

2. PATINDEX ( '%pattern%' , expression )

The return value is the first position that satisfies the pattern, and if not met, the return value is 0

Determine if a number type

PATINDEX ('%[^0-9]% ', expression)

The return value is 0 , it is a purely numeric type

The notation for supporting decimal and positive numbers is

PATINDEX ('%[^0-9|.| -|+]% ', expression)

A number is judged in SQL Server (the. 3 is automatically recognized as 0.3)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.