Using VS2013 to create a database project implementing the MSSQL regularization method

Source: Internet
Author: User

Implementation steps

1: Create a database project



2: Refer to the relevant library, simple implementation code as follows


Using system;using system.data;using system.data.sqlclient;using system.data.sqltypes;using Microsoft.sqlserver.server;using system.text.regularexpressions;public Partial class regexsql{    [ Microsoft.SqlServer.Server.SqlFunction] public    static SqlBoolean regex_ismatch (string input, String Regex)    {        return new SqlBoolean (Regex.IsMatch (input, Regex, regexoptions.ignorecase));    }    [Microsoft.SqlServer.Server.SqlFunction]    public static SqlString Regex_match (string input, String Regex)    {        return new SqlString (Regex.match (Input, regex , Regexoptions.ignorecase). Value);}    }

3: Add an assembly in MSSQL




If it fails, execute the script first

exec sp_configure ' show advanced options ', ' 1 '; goreconfigure;goexec sp_configure ' clr enabled ', ' 1 ' goreconfigure;exec sp _configure ' Show advanced Options ', ' 1 ';  Go  ALTER DATABASE [db_name] Set trustworthy on;go

4: Create an association function

Create function Regex_match (@input as nvarchar, @regex as  nvarchar) returns nvarchar (  +) as External  name iftrue_regex.regexsql.regex_match;gocreate function regex_ismatch (@input as nvarchar (+), @regex as  nvarchar (+)) returns Bitas  external  name Iftrue_regex.regexsql.regex_ismatch;go

5: Using functions to implement regular matching

  SELECT dbo. Regex_ismatch (' abcde123asdf234 ', ' [b-s]+ ')  select dbo. Regex_match (' abcde123asdf234 ', ' [b-s]+ ')

Note: The above implementation is based on framework3.5, in the framework4.0 to add the assembly error, the same way can implement many of the database itself is inconvenient to implement functions, such as: Call Web API, WebService, etc.

Code download

Using VS2013 to create a database project implementing the MSSQL regularization method

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.