日期:2014-05-17 浏览次数:20537 次
--創建自定義函數
CREATE FUNCTION [dbo].[fe_str]
(
@p1 VARCHAR(MAX)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @r VARCHAR(MAX)
SET @r=''
;
WITH a1 AS
(
SELECT @p1 z1,CAST('' AS char(1)) z2,1 n
UNION ALL
SELECT z1,
CAST(CASE WHEN SUBSTRING(z1,n,1) LIKE '[0-9a-zA-Z]' THEN SUBSTRING(z1,n,1) ELSE ' ' END AS CHAR(1)),
n+1
FROM a1
WHERE n<=LEN(z1)
)
SELECT @r=@r+z2 FROM a1 WHERE z2<>''
OPTION(MAXRECURSION 0)
RETURN @r
END
GO
--調用自定義函數
SELECT dbo.fe_str('0-28080$ 612#-0ABC')