Skip to content

Instantly share code, notes, and snippets.

@BenjaminAdams
Last active March 1, 2022 19:04
Show Gist options
  • Save BenjaminAdams/df9e8585f1fd55130674 to your computer and use it in GitHub Desktop.
Save BenjaminAdams/df9e8585f1fd55130674 to your computer and use it in GitHub Desktop.
Search a SQL server field for a creditcard number
SET ROWCOUNT 10000
SELECT SomeField
FROM tablename
WHERE patindex('%[3|4|5|6][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',SomeField) > 0
or to get the unique numbers
SET ROWCOUNT 50
SELECT distinct SUBSTRING (SomeField ,patindex('%[3|4|5|6][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',SomeField) , 12 )
FROM tablename
WHERE patindex('%[3|4|5|6][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',SomeField) > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment