MSSQL SQL Server verifies integer function sharing

Source: Internet
Author: User
Tags mssql

Transferred from: http://www.maomao365.com/?p=6227

Summary:
The following is a function that Isnumber validates an integer to make a numerical judgment in a SQL script, as follows:

Cases:
The principle of implementation: to determine whether to include special characters, whether all 0-9 of the natural number composition

 CREATE FUNCTIONDbo.check_number (/*verifies whether a string type is an integer numeric type*/@checkTmp VARCHAR( -))RETURNS BITBEGINDECLARE @tmp BITIF  Left(@checkTmp,1)= '-'SET @checkTmp = SUBSTRING(@checkTmp,2,LEN(@checkTmp))IF(PATINDEX('%[^0-9-]%',@checkTmp)= 0 and CHARINDEX('-',@checkTmp)<= 1 and @checkTmp  not inch('.','-','+','^') and LEN(@checkTmp)>0 and @checkTmp  not  like '%-%')SET @tmp = 1ELSESET @tmp = 0RETURN @tmpENDGO/*Data Validation*/SELECT '878' [Test Values], Dbo.check_number ('999')[Test return value];SELECT 'TestData' [Test Values], Dbo.check_number ('ABC')[Test return value];SELECT '8-8' [Test Values], Dbo.check_number ('9+9')[Test return value];SELECT '8.9' [Test Values], Dbo.check_number ('$9.9')[Test return value];SELECT 'maomao365.com' [Test Values], Dbo.check_number ('maomao365.com')[Test return value];GoDrop functionCheck_number

MSSQL SQL Server verifies integer function sharing

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.