문자열 추출 숫자/한자/영문 자모

4166 단어
-- ========================================
-- Author:<Oliver QIN>
-- Date  :<2016/01/13>
-- Desc  :<       /  /    >
-- ========================================
--    
IF OBJECT_ID('dbo.Fn_Get_Number') is not null
drop function dbo.Fn_Get_Number
GO
CREATE FUNCTION dbo.Fn_Get_Number(@str VARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX('%[^0-9]%',@str) > 0
BEGIN
set @str=stuff(@str,patindex('%[^0-9]%',@str),1,'')
END
RETURN @str
END
--    
go
select  dbo.Fn_Get_Number('sg12jjf34djs')  as '         '
-------------------------------------------------------------
---    
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('%[^ - ]%',@S) > 0
SET @S = STUFF(@S,PATINDEX('%[^ - ]%',@S),1,N'')
RETURN @S
END
GO
PRINT DBO.CHINA_STR('  ABC123ABC')
GO
------------------------------    
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
--  
PRINT DBO.GET_STR('ABC123g')
GO

좋은 웹페이지 즐겨찾기