Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing characters in Fields

Status
Not open for further replies.
Dec 11, 2009
60
US
I have a SSN field: 000000000

I want it to print out as :

***-**-0000

How can I accomplish this?

Thanks for any suggestions!
 
You can use the stuff function the add the dashes, like this...

Code:
Declare @SSN VarChar(20)

Set @SSN = '123456789'

Select Stuff(Stuff(@SSN,6, 0, '-'), 4, 0, '-')

Do you mean that you literally want to see the *'s instead of the actual number?

If so, it's even easier.

Code:
Declare @SSN VarChar(20)

Set @SSN = '123456789'

Select '***-**-' + Right(@SSN, 4)


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top