A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Kaumil Gandhi ,
Welcome to the microsoft TSQL Q&A forum!
Please check:
;WITH cte as
(SELECT *,
CASE WHEN PATINDEX('%[0-9]%/[0-9]%',notes)<>0
THEN PATINDEX('%[0-9]%/[0-9]%',notes)
ELSE PATINDEX('%[0-9]%.[0-9]%',notes) END num
FROM #Temp)
,cte2 as(SELECT *,SUBSTRING(notes,num,
CASE WHEN PATINDEX('%[0-9] [A-Z]%',notes)=0
THEN LEN(notes)-num+1
ELSE PATINDEX('%[0-9] [A-Z]%',notes)-num+1 END) [date]
FROM cte)
SELECT id,notes,TRY_CONVERT(date,[date]) [date]
FROM cte2
ORDER BY id,TRY_CONVERT(date,[date])
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.