I need to find a continuous date in a string from column name Filename. The string has other numbers in it with dashes(or another character, like an underscore), but I only need the continuous number
The Date needs to be extracted from the filename. (I know the data is just wow, multiple vendors, multiple file naming formats is the cause.)
This question is similar to this question, but it's looking for something different with a different requirement: TSQL: Find a continuous number in a string
Desired result:
Actual Result:
Test Code:
DROP TABLE #dob
CREATE TABLE #dob (
FILENAME VARCHAR(MAX)
,StudentID INT
)
INSERT INTO #dob
( FILENAME )
VALUES
('Smith John D, 11-23-1980, 1234567.pdf')
,('Doe Jane, _01_22_1980_123456.pdf')
,('John Doe, 567891.pdf' )
--This is what I tried.
SELECT FILENAME
, substring(FileName, patindex('%[0-9][%-%][%_%][0-9][0-9][0-9][0-9][0-9]%', FileName), 8) AS dob
FROM #dob