I would like to replace the all digits in a number with *, other than the last 4.
Here is my table:
Person
-----------
PersonID PersonBadgeNumber numeric(16,0)
I would like to replace the all digits in a number with *, other than the last 4.
Here is my table:
Person
-----------
PersonID PersonBadgeNumber numeric(16,0)
Something like this will work...
DECLARE @badgeId Numeric(16, 0) = 1238985495;
SELECT
REPLICATE('*', LEN(@badgeId) - 4) +
RIGHT(@badgeId, 4);
-- Produces: ******5495
To use it in a query do this:
SELECT
REPLICATE('*', LEN(PersonBadgeNumber) - 4) +
RIGHT(PersonBadgeNumber, 4) RedactedBadgeNumber
FROM Person;