SQLTeam.com | Weblogs | Forums

How to hide few digits of account number

Input , output.
123456, ****56,
234654, ****54,
543123, ****23,
Can anyone suggest me on the query.

my one idea
Replace with * using Regular Expressions

my second idea
cut paste ... divide by 1000

my third idea
SQL Server may have something ..readily available .. Please google search

1 Like
declare @santosh table(Input  int);

insert into @santosh
select 123456 union
select 234654 union
select 543123

select *, STUFF(cast(Input as varchar(10)), 1, 4, '****') 
From @santosh

but this would require knowing length of input column, how long or how short the possible values of input can be. what data type it is etc

Is this just for display purposes - or is there a security requirement involved? If the only concern is display then you might want to look at data masking which would automatically mask the data.

However - if there is a security component, then you really need to look at encryption.

If it is only for a single query then you can use various techniques to 'mask' all but the last 2 characters.