SQLServerCentral.com / SQL Server 2005 / T-SQL (SS2K5) / Masking SSN / Latest PostsInstantForum.NET v2.9.0SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comTue, 31 Mar 2015 14:58:56 GMT20RE: Masking SSNhttp://www.sqlservercentral.com/Forums/Topic1434452-338-1.aspxI understand the challenges here but why in the world do you have a table with SSN in them like this? This type of thing should not be in your database. It is one thing if you need store SSN (encrypted I hope) but it is another to have them thrown into comments like this.I used the delimitedSplit8K function for this. To find the code for this function please follow the link in my signature about splitting strings.[code];with SSN (RawData)as( select '123-45-6789 John Doe' union all select 'Applied Payment For 123-45-7689 John Doe' union all select '999-78-9909 Blue Sky' union all select 'Applied Payment For 898-85-5895 Green River' )select stuff(RawData, charindex(Item, RawData), 6, 'XXX-XX') as Fixedfrom SSNcross apply dbo.DelimitedSplit8K(RawData, ' ')where Item like '%[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]%'[/code]Fri, 22 Mar 2013 12:56:37 GMTSean LangeMasking SSNhttp://www.sqlservercentral.com/Forums/Topic1434452-338-1.aspxI am not certain how to mask first 5 digit of SSN w/in a column when the column has distinct values.Here is a sample of my dataset. The column = Details.Details-------------123-45-6789 John DoeApplied Payment For 123-45-7689 John Doe999-78-9909 Blue SkyApplied Payment For 898-85-5895 Green RiverIf I use the following syntax:Select 'XXX-XX-+Substring (Details,8,255) DetailsFrom Test;The result would look something like this:Details----------------------XXX-XX-6789 John DoeXXX-XX-ed Payment For 123-45-7689 John DoeXXX-XX-9909 Blue SkyXXX-XX-ed Payment For 898-85-5895 Green RiverInstead, I'd like to know how to display the result into this format:Details--------------------XXX-XX-6789 John DoeApplied Payment For XXX-XX-7689 John DoeXXX-XX-9909 Blue SkyApplied Payment For XXX-XX-5895 Green RiverFri, 22 Mar 2013 12:03:53 GMTJStevenson1