Retrieve date from description in SQL server 2008 R2

  • Hi I want to retrieve date from description.

    Following is the code I am using it now,But I have to write this syntax 12 times for each different month.

    I mean below example is for Jan.if I have @desc='Call: (FM) abc Co Feb 21 12 $219.5 (100 Shs)' then I have to add one more case condition.

    Is there any simple way to do this?

    DECLARE @desc VARCHAR(200)='Call: (MF) xyz Co Jan 21 12 $219.5 (100 Shs)'

    SELECT CASE WHEN @desc LIKE '%Jan%'

    THEN SUBSTRING(@desc,PATINDEX('%Jan%',@desc)

    ,PATINDEX('%[$]%',@desc)-PATINDEX('%Jan%',@desc)) END

  • I got it on my own.

    Below is the Answer:

    SELECT SUBSTRING(@desc, PATINDEX('%[$]%', @desc)-11,11)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply