Share via

Extra the file name

L Tune 80 Reputation points
2023-12-29T07:42:15.8733333+00:00

I have a file named Team_worksales_2023-12-20.xlsx

I want to extract date value 2023-12-20 with the derived column.

I tried to use findstring but it gives the value 2023-12-20.xlsx

How to remove the.xlsx?

SQL Server Integration Services
{count} votes

Answer accepted by question author
  1. ZoeHui-MSFT 41,541 Reputation points
    2023-12-29T08:03:42.58+00:00

    Hi @L Tune,

    You may try with below expression.

    Left(TOKEN(@[User::FileName], "_", 3),10)
    

    or

    left(right(@[User::FileName],15),10)
    
    
    

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Azar 31,630 Reputation points MVP Volunteer Moderator
    2023-12-29T07:58:40.4866667+00:00

    Hi L Tune

    you can use a combo of string functions in your expression. Assuming you are working with SSIS and using a derived column transformation,

    (DT_STR, 10, 1252) SUBSTRING(FINDSTRING([YourFileNameColumn], "_", 1) + 1, 10)
    

    Replace file name with the actual column name that contains the file name. This assumes that the date portion is always in the format "YYYY-MM-DD" and is preceded by an underscore in the filename.

    IIf this helps kindly acce[pt the answer thanks much.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.