Dynamic content for filename using instr

sam nick 366 Reputation points
2021-04-17T04:01:18.683+00:00

Hi,
I have a Foreach loop and within it is a copy activity to load data from blob to sql. Since there are multiple files and tables, i want to set the Sink table name to be dynamic but by very specific name.

Ex: Filename: 1234_SalesData_Prod.csv and i'd like the table name to be SalesData
Filename: Asfc234_MarketData_Prod.csv and i'd like the table name to be MarketData.

The _Prod will not change, the initial characters can change. I tried using an instr but i get the error 'instr' is not a recognized function. Please advise on how to achieve this instr and subtring combination.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
{count} votes

1 answer

Sort by: Most helpful
  1. MartinJaffer-MSFT 26,161 Reputation points
    2021-04-19T15:47:00.727+00:00

    Hello @sam nick and welcome to Microsoft Q&A.

    It looks like you want to extract the middle part of the file name.

    If we can make the assumption that all your file names follow the form "part1_TableName_part3" , having exactly 3 parts, separated by _ , then we can construct an expression to retrieve the TableName.

    @split(pipeline().parameters.filename,'_')[1]  
    

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.