Thursday, 3 October 2013

How to masking in SQL server

CREATE  FUNCTION [dbo].[fn_text_masking]
(
 @in_input VARCHAR(MAX),
 @in_mask_len INT
)
RETURNS VARCHAR(MAX)
AS
BEGIN
 DECLARE @mask_text VARCHAR(MAX), @mask_char VARCHAR(20)
 SET @mask_char = 'XXXXXXXXXXXXXXXXXXXX'

 SELECT @mask_text = REPLACE(@in_input, SUBSTRING(@in_input, 1, LEN(@in_input) - @in_mask_len),
SUBSTRING(@mask_char, 1, LEN(@in_input) - @in_mask_len))

 RETURN @mask_text
END
------------------------------------------------
SELECT dbo.fn_text_masking('123456789',4)

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...