WITH CTE AS
(
SELECT '"$1,277.50 *. 20231231_SBMA_PMPM' AS INVOICE_FILE
UNION ALL SELECT '$1.489.21"",20231231_SBMA_PMPM"'
UNION ALL SELECT '$1,640.00.20231231_S8MA_PMPM'
UNION ALL SELECT '$2,124.94,20231231_SBMA_PMPM'
UNION ALL SELECT '$3,601.10,20231231_S8MA_PMPM'
UNION ALL SELECT '$4,187.56",20231231_SBMA_PMPM_Captive '
UNION ALL SELECT '"$6.441.02 *. 20231231_S8MA_PMPM '
UNION ALL SELECT '$0.00.$10.024.32"".20231231_SBMA_PMPM" '
UNION ALL SELECT '$0.00."$2.667.29".20231231_SBMA_PMPM_Captive '
UNION ALL SELECT '$0.00."$6.808.21 ".20231231_SBMA_PMPM '
UNION ALL SELECT '$0.00 .$0.00."$13,988.26".20231231_SBMA_PMPM '
UNION ALL SELECT '20231231_SBMA_PMPM '
UNION ALL SELECT '20231231_SBMA_PMPM_Captive'
)
SELECT
SUBSTRING(INVOICE_FILE,
PATINDEX('%[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%', INVOICE_FILE), 8) AS ExtractedDate
FROM CTE