Sqlserver extracts Chinese characters, numbers, and letters from the content

Source: Internet
Author: User
-- Retrieve the number IFOBJECT_ID (DBO. GET_NUMBER2) ISNOTNULLDROPFUNCTIONDBO. GET_NUMBER2GOCREATEFUNCTIONDBO.GET_NUMBER2 (@ SVARCHAR (100) RETURNSVARCHAR (100) ASBEGINWHILEPATINDEX (% [^ 0-9] %, @ S) 0BEGINset @ sstuff (@ s, patindex (% [^ 0-9] %, @ s ),

-- Retrieve the number IF OBJECT_ID (DBO. GET_NUMBER2) is not null drop function dbo. GET_NUMBER2 go create function dbo. GET_NUMBER2 (@ s varchar (100) returns varchar (100) as begin while patindex (% [^ 0-9] %, @ S) 0 BEGIN set @ s = stuff (@ s, patindex (% [^ 0-9] %, @ s ),

-- Retrieve numbers

IF OBJECT_ID ('dbo. GET_NUMBER2 ') IS NOT NULL

Drop function dbo. GET_NUMBER2

GO

Create function dbo. GET_NUMBER2 (@ s varchar (100 ))

Returns varchar (100)

AS

BEGIN

While patindex ('% [^ 0-9] %', @ S)> 0

BEGIN

Set @ s = stuff (@ s, patindex ('% [^ 0-9] %', @ s), 1 ,'')

END

RETURN @ S

END

GO

-- Test

Print dbo. GET_NUMBER ('Ha abc123abc ')

GO

-- 123

--------------------------------------------------------------------

-- Retrieve English

IF OBJECT_ID ('dbo. GET_STR ') IS NOT NULL

Drop function dbo. GET_STR

GO

Create function dbo. GET_STR (@ s varchar (100 ))

Returns varchar (100)

AS

BEGIN

While patindex ('% [^ a-z] %', @ S)> 0

BEGIN

Set @ s = stuff (@ s, patindex ('% [^ a-z] %', @ s), 1 ,'')

END

RETURN @ S

END

GO

-- Test

Print dbo. GET_STR ('Ha abc123abc ')

GO

--------------------------------------------------------------------

-- Extract Chinese

IF OBJECT_ID ('dbo. CHINA_STR ') IS NOT NULL

Drop function dbo. CHINA_STR

GO

Create function dbo. CHINA_STR (@ s nvarchar (100 ))

Returns varchar (100)

AS

BEGIN

While patindex ('% [^ A-seat] %', @ S)> 0

SET @ S = STUFF (@ S, PATINDEX ('% [^ A-seat] %', @ S), 1, n '')

RETURN @ S

END

GO

Print dbo. CHINA_STR ('Ha abc123abc ')

GO

SELECT * FROM (select 'asdkg; Comment K Unicom DL 'as col) tb where col like n' % [A-Snapshot] %'

,

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.