USE [CRM]
GO
/****** Object: UserDefinedFunction [dbo].[F_NumberDispose] Script Date: 2020/10/14 15:18:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--/*********************************************************************************************************
--建立者: Herman 日期﹕2014-1-9
--调用的程序﹕
--说明﹕手机号码、证件号码等隐藏部分信息
--更新记录﹕
-- 日期 更改人 更新说明
------------------ ------------- --------------------------------------------
-- 2014-1-9 Herman 新增
-- 2020-08-15 Herman 18位身份证隐藏年月
----*********************************************************************************************************/
ALTER FUNCTION [dbo].[F_NumberDispose]
(
@numberStrOld VARCHAR(30)
)
RETURNS VARCHAR(30)
AS
BEGIN
DECLARE @numberStrNew VARCHAR(30)
DECLARE @strLength INT
SET @strLength = LEN(@numberStrOld)
SELECT @numberStrNew = ( CASE WHEN @strLength = 18
THEN STUFF(@numberStrOld, 9,
@strLength - 14,
REPLICATE('*',
@strLength - 14))
WHEN @strLength > 9
THEN STUFF(@numberStrOld, 5,
@strLength - 7,
REPLICATE('*',
@strLength - 7))
WHEN @strLength > 7
THEN STUFF(@numberStrOld, 4,
@strLength - 5,
REPLICATE('*',
@strLength - 5))
WHEN @strLength > 4
THEN STUFF(@numberStrOld, 3,
@strLength - 4,
REPLICATE('*',
@strLength - 4))
WHEN @strLength > 2
THEN STUFF(@numberStrOld, 2,
@strLength - 2,
REPLICATE('*',
@strLength - 2))
ELSE @numberStrOld
END )
RETURN @numberStrNew
END
网友评论