SQL Server extracts Chinese characters, numbers, letters in content

Source: Internet
Author: User

--Remove the numbers

IF object_id (' DBO. Get_number2 ') is not NULL

DROP FUNCTION DBO. Get_number2

Go

The 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 (' hehe abc123abc ')

Go

--123

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

--Take out English

IF object_id (' DBO. Get_str ') is not NULL

DROP FUNCTION DBO. Get_str

Go

The 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 (' hehe abc123abc ')

Go

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

--Take out Chinese

IF object_id (' DBO. China_str ') is not NULL

DROP FUNCTION DBO. China_str

Go

The CREATE FUNCTION DBO. China_str (@S NVARCHAR (100))

RETURNS VARCHAR (100)

As

BEGIN

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

SET @S = STUFF (@s,patindex ('%[^ acridine-seat]% ', @S), 1,n ')

Return @S

End

Go

PRINT DBO. China_str (' hehe abc123abc ')

Go

SELECT * FROM (SELECT ' asdkg altar k unicom dl ' as col) TB WHERE col like N '%[acridine-]% '

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.