-3

I want to some column masking in sql column.

How can I do sql command?

1 Answers1

1

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;

enter image description here

Demo

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360