In Microsoft SQL Server 2016 I have a numeric column with values of varying lengths. I'd like to display the last three digits and mask the others.

EDIT: Can this be done just in the `SELECT` statement without going through the Dynamic Data Masking process (creating a table, setting permissions, etc.)?

For example:  

`20639636
23155`

Returns:  

`XXXXX636
XX155`

I used a version of @Alan Burstein's answer. Values less than three digits return NULL but that is not relevant for my needs.

```
WITH t AS (
SELECT 123456123 AS N UNION
SELECT 12312 UNION
SELECT 1234  UNION
SELECT 333   UNION
SELECT 22
)
SELECT t.N
     , REPLICATE('X', LEN(t.N)-3) + RIGHT(t.N,3) AS N_MASKED
  FROM t
;

N           N_MASKED
22          NULL
333         333
1234        X234
12312       XX312
123456123   XXXXXX123

```