views:

616

answers:

2

I have a string in a MS 2000 SQL db and need to remove just the SSN using the select satement. I don't have the option of using an external app. The other fun part is that the locaton of the SSN is not always the same.

[B-Day][First Name][SSN][POB]
12121970John123-45-6789Las Vages

Or

[B-Day][First Name][Last Name][SSN][POB]
12121970JohnDoe123-45-6789Las Vages

I need RegEx of the SQL variety!

Any ideas?

+2  A: 

Assuming you have access to the server itself, here is an article which describes how to add a Regex function using VBScript to MSSQL 2000. From there the regex for matching a SSN is quite simple ([0-9]{3}-[0-9]{2}-[0-9]{4}). You may need to expand the function provided in the article to support replacing as well as matching.

Rex M
This is good answer and is more generic. But I don't have access to the server in this case. Thanks!
NitroxDM
+2  A: 
shahkalpesh
I had to change things a little but it got me started. Thanks!SELECT substring(a, 1, PatIndex('%[0-9][0-9][0-9]-%', a) - 1) + substring(a, PatIndex('%-[0-9][0-9][0-9][0-9]%', a) + 5, 100)FROM testTable
NitroxDM