Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Data formatting SSN
From Wiki
You should not store unencrypted SSNs in the database. If you do store them and you don't have the dashes but you need to display them then you can use the STUFF function to accomplish that Here is an example, the output will be 111-22-3333
- DECLARE @SSN VARCHAR(11)
- SELECT @SSN ='111223333'
- SELECT STUFF(STUFF(@SSN,4,0,'-'),7,0,'-')
You can also use STUFF to hide the last 4 characters for example.
- DECLARE @SSN VARCHAR(11)
- SELECT @SSN ='111223333'
- SELECT STUFF(@SSN,6,4,'----')
Of course you could have LEFT instead
- DECLARE @SSN VARCHAR(11)
- SELECT @SSN ='111223333'
- SELECT LEFT(@SSN,5) +'----'
Contributed by: --SQLDenis 02:49, 31 May 2008 (GMT)
Part of SQL Server Programming Hacks
Section Handy tricks



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.