MSSQL SQL Server verifies integer function sharing

Source: Internet
Author: User
Tags mssql

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

例:实现原理:判断 是否包含特殊字符,是否全部为0-9的自然数组成    CREATE FUNCTION dbo.check_number(/*验证一字符串类型是否为整型数值类型*/@checkTmp VARCHAR(100))RETURNS BITBEGINDECLARE @tmp BITIF LEFT(@checkTmp, 1) = ‘-‘SET @checkTmp = SUBSTRING(@checkTmp, 2, LEN(@checkTmp))IF (PATINDEX(‘%[^0-9-]%‘, @checkTmp) = 0AND CHARINDEX(‘-‘, @checkTmp) <= 1AND @checkTmp NOT IN (‘.‘, ‘-‘, ‘+‘, ‘^‘)AND LEN(@checkTmp)>0AND @checkTmp NOT LIKE ‘%-%‘)SET @tmp = 1ELSESET @tmp = 0RETURN @tmpENDGO/*数据验证*/SELECT ‘878‘ [测试数值],dbo.check_number(‘999‘) [测试返回值];SELECT ‘testData‘ [测试数值],dbo.check_number(‘abc‘) [测试返回值];SELECT ‘8-8‘ [测试数值],dbo.check_number(‘9+9‘) [测试返回值];SELECT ‘8.9‘ [测试数值],dbo.check_number(‘$9.9‘) [测试返回值];SELECT ‘maomao365.com‘ [测试数值],dbo.check_number(‘maomao365.com‘) [测试返回值];godrop function check_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.