1

I have a huge VARCHAR field, that is a body of an email. There could be any sort of text on either side of the email. I want to see if anyone listed their Social security number anywhere in the text.

In the WHERE clause, I tried

WHERE X.Description LIKE '%___-__-____%'    

Is there a way to find a numeric string that looks like 111-11-1111 or 111 11 1111

baineschile
  • 139
  • 2
  • 10

4 Answers4

1
WHERE X.Description LIKE '%[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]%'  
Xedni
  • 3,662
  • 2
  • 16
  • 27
1

I don't think you can guarantee that the separator for SSNs is always a hyphen. In SQL Server, you could find examples using like:

where X.Description LIKE '%[0-9][0-9][0-9][- ][0-9][0-9][0-9][- ][0-9][0-9][0-9][0-9]%'

In MySQL, you would use regular expressions:

where X.Description regexp '[0-9]{3}[- ][0-9]{3}[- ]{4}'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

I would add a space between each bracket and % to be safe like this:

WHERE X.Description LIKE '% [0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9] %'

Otherwise the code would incorrectly think something like this is an SSN: 12343444-76-878787878

Daniel Marcus
  • 2,686
  • 1
  • 7
  • 13