I want to some column masking in sql column.
How can I do sql command?
I want to some column masking in sql column.
How can I do sql command?
Assuming you are using SQL Server 2008 or later, we can try using REPLICATE
with SUBSTRING
:
SELECT
'**' + SUBSTRING(col, 3, 2) + REPLICATE('*', LEN(col) - 4) AS mask
FROM yourTable;
A nicer way to handle this would be to make use of regular expressions, but SQL Server does not really support a regex replace. So I offer this as an alternative.