0

I need to replace this number's 1234567891011 first and last four digits with stars.

How should I do it with replace function?

1 Answer 1

2

Use substring function instead of replace and concatenate stars with "middle" part of your string:

declare @str nvarchar(max)
select @str = '1234567891011'

select '****' + substring(@str, 5, len(@str) - 8) + '****'

Output:

****56789****
Sign up to request clarification or add additional context in comments.

3 Comments

Andy Thanks for reply, I will try solution and will let you know.!
Andy can you please explain syntax of substring, so I can further modify as per my requirement what if I need to replace middle 4 digits.?
@AkkiBhogte See msdn.microsoft.com/en-us/library/ms187748.aspx for reference on this function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.