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