SQL Server methods for extracting Chinese characters/numbers/letters

Source: Internet
Author: User

QL Server method for extracting Chinese characters/numbers/letters

--Extracting 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 (' hehe abc123abc ')
GO
--123
--------------------------------------------------------------------
--Extract 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 (' hehe 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 ('%[^-seat]% ', @S) > 0
SET @S = STUFF (@s,patindex ('%[^ acridine-block]% ', @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-]% '

SQL Server methods for extracting Chinese characters/numbers/letters

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.