DECLARE @Contents varchar(4000)
SET @Contents =
'abcdef 01/01/2018 08:15:13 This is a note , this is a note , this is a note , this is a note , this is a note , this is a note , this is a note, ghijkl 02/02/2018 12:15:45, this is a note , this is a note , this is a note , this is a note mnopqr 03/02/2018 10:34:23 this is a note this is a note this is a note this is a note this is a note this is a note';
WITH Ten AS (
SELECT n FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (0)) v(n)
)
, Hundred AS (
SELECT t1.n
FROM Ten t1
CROSS JOIN Ten t2
)
, Thousand(n) AS (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
FROM Hundred h
CROSS JOIN Ten t
)
, StartPoints AS (
SELECT n AS StartChar
FROM Thousand
WHERE SUBSTRING(@Contents,n,7) LIKE '[a-z][a-z][a-z][a-z][a-z][a-z] '
AND ISDATE(SUBSTRING(@Contents,n+7,19)) = 1
AND n<= LEN(@Contents) - 26
)
, StartPointssandNext AS (
SELECT
StartChar
, LEAD(StartChar,1,LEN(@Contents)+1) OVER (ORDER BY StartChar) AS NextStartChar
FROM StartPoints
)
SELECT
SUBSTRING(@Contents,StartChar,NextStartChar-StartChar)
FROM StartPointssandNext
John