I have this sp. I just found out that M.MDS_FILE column, contains a file name as this:
adlu201008261156_3.zip. The submission date is embedded in the file name.
How can I pick out this date? 20100826 this portion and use in the sp? that is the date needed to use here:
instead of GETDATE.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[GET_SCHEDULE_SUBMITTED_DETAIL]
@FACILITYKEY varchar(1000),
@UNITSTR VARCHAR(100),
@FromDate datetime,
@ToDate datetime
AS
BEGIN
SELECT S.FACILITY_KEY, S.PAT_NUMBER, S.A3A_DATE_USER, M.REFERENCE_DATE ,
RTRIM(P.LAST_NAME) + CASE WHEN RTRIM(P.FIRST_NAME) <> '' THEN ', '
ELSE ''
END + RTRIM(P.FIRST_NAME) PATIENT_NAME
,CASE WHEN P.NURSING_UNIT is not null THEN P.NURSING_UNIT ELSE '' END NURSING_UNIT
,CASE WHEN P.UNIT_CODE is not null THEN P.UNIT_CODE ELSE '' END UNIT_CODE, 'SUBMITTED' AS ASSESSMENTS
FROM [OPTC].MDS_M_SCHEDULE S INNER JOIN OPTC.MD3_M_MAST M
ON S.PAT_NUMBER=M.PAT_NUMBER
LEFT JOIN OGEN.GEN_M_PATIENT_MAST P ON S.PAT_NUMBER = P.PAT_NUMBER
WHERE S.PAT_NUMBER=M.PAT_NUMBER AND M.REFERENCE_DATE < GETDATE()
AND S.A3A_DATE_USER BETWEEN @FromDate AND @ToDate
AND M.SIGN_DATE IS NOT NULL AND M.MDS_FILE IS NOT NULL AND S.FACILITY_KEY IN (SELECT Value FROM dbo.ListToTable(@FACILITYKEY,','))
AND ( @UNITSTR IS NULL
OR @UNITSTR = ''
OR CHARINDEX(P.UNIT_CODE, @UNITSTR)% 2 = 1 )
END
You didn’t mention which database this is, but most have a function for performing a regex match on a string. For instance, Oracle has REGEXP_SUBSTR. Run that on the column, with the proper regex (something like
\d{12}) and then parse the result as a date.Edit: And consider changing your schema as posted in the earlier answer – if possible because this won’t be super efficient.