How to get specific string/Date from a string in SQL Server using TSQL

Questions: How you will get all dates from below string, I have also include answer, it is done by recursive CTE

Comments

  1. DECLARE @S VARCHAR(MAX) =
    '09/14/2017:Your SR is ON HOLD - This is the final reminder to provid09/15/2017e 09/13/2017:Your
    09/12/2017:Your SR is ON HOLD - We require the clarification from you on 254119.
    A SR has been received by DMS and its execution09/18/2017 is in progress.
    A SR has been received by SDS and09/25/2017 execution has not yet started on it.
    A SR has been received by SDS and execution has not yet started on it.'

    ;WITH CTE AS
    (
    SELECT SUBSTRING(@S,CHARINDEX('/2017',@S)-5,10) AS [Date] ,SUBSTRING(@S,CHARINDEX('/2017',@S)+5,LEN(@S)) AS S
    UNION ALL
    SELECT SUBSTRING(S,CHARINDEX('/2017',S)-5,10) AS [Date],SUBSTRING(S,CHARINDEX('/2017',S)+5,LEN(S))
    AS S FROM CTE WHERE CHARINDEX('/2017',S) > 0
    )
    SELECT * FROM CTE

    ReplyDelete
  2. very helpful.
    Thanks admin

    ReplyDelete

Contact Form

Send