Replace numbers with asterisks


I want to replace the first all the numbers of 15 characters of a 19 digit number with asterisks. Is this possible using a SQL command?


input: 1234 3456 7890 1234
result: **** **** **** 1234

Open in new window

Who is Participating?
mfsamuelConnect With a Mentor Commented:
Try this.
SELECT '**** **** **** '+SUBSTRING(input, 16, 4)
FROM table_name

Open in new window

Use the substring function as part of an update e.g.

update table
set col = '***************' + substr(col,16,4)
Sorry, the substr function is called substring in SQL Server, not substr.  I was thinking with my Oracle hat on!

You may be able to omit the 3rd option (4 in the example) to give all characters to the end of the string.  This is valid in Oracle, but not sure about SQL Server.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

select '**** **** **** ' + right(YourField,4)
we all answered basically the same within seconds it seems. :)
egxisAuthor Commented:
Wow - that was quick. This is a tough one as you all answered similarly, but techncally mfsamuel was most correct.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.