Ok - I got tired of repeatedly modifying my favorite duplicate deletion algorithm for whatever table I happen to be working with at the time. This code is the result of that frustration. It provides hassle free locating and reporting (or deletion) of duplicate rows in a SQL table based on the uniqueness of a column or columns that the user provides with a few nifty hands-off features. The actual deletion method employed is a correlated subquery, so I must locate or create a column of unique values.
This function accepts a phone number as a string and does its best to tear it apart and return the various pieces (e.g. area code, last four, etc.) It returns the phone number in a format specified by the parameters passed in.