SQL Server extracts Chinese, English, and digital from a string

Source: Internet
Author: User

--"Extract Chinese"
IF object_id (' DBO.FUN_GETCN ') is not NULL
DROP FUNCTION DBO.FUN_GETCN
GO
Create function DBO.FUN_GETCN (@str varchar (4000))
Returns varchar (4000)
As
Begin
DECLARE @word nchar (1), @CN varchar (4000)
Set @CN = ' '
While Len (@str) >0
Begin
Set @word =left (@str, 1)
If Unicode (@word) between 19968 and 40869
Set @[email Protected][email protected]
Set @str =right (@str, Len (@str)-1)
End
Return @CN
End
GO

SELECT DBO.FUN_GETCN (' Turing me 666QQ Chinese AK123 ')


--"Extract Chinese"
IF object_id (' Dbo.get_chinese ') is not NULL
DROP FUNCTION Dbo.get_chinese
GO
CREATE FUNCTION Dbo.get_chinese (@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
SELECT Dbo.get_chinese (' Turing me 666QQ Chinese AK123 ')



--"extract numbers"
IF object_id (' dbo. Get_number ') is not NULL
DROP FUNCTION dbo. Get_number
GO
CREATE FUNCTION dbo. Get_number (@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

SELECT DBO. Get_number (' Turing me 666QQ Chinese AK123 ')


--"extract English"
IF object_id (' dbo.get_english ') is not NULL
DROP FUNCTION Dbo.get_english
GO
CREATE FUNCTION dbo.get_english (@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

SELECT dbo.get_english (' Turing me 666QQ Chinese AK123 ')

SQL Server extracts Chinese, English, and digital from a string

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.