Search code examples
azure-data-factory

How to concatenate a parameter?


I have the following configuration in my Pipeline expression builder in our copy activity

@concat('SELECT * FROM ', pipeline().parameters.Domain, 
        '.', pipeline().parameters.TableName)

This will successfully copy data to our SQL Server table as dbo.MyTable.

I would like to add suffix or some additional character to end of the table so that it copies to the SQL Server database as dbo.MyTableV2.

Can someone let me know how to add additional characters to the table?

For example, this doesn't work:

@concat('SELECT * FROM ', pipeline().parameters.Domain, 
        '.', pipeline().parameters.TableName, 'V2')

Any thoughts?


Solution

  • I do agree with @Nandan that the reason for the above error is when the given table name does not exist in the source database.

    I have tried the above expression in a copy activity source query, and you can see it gave the same error as there is no PolicyV2 table in my source database.

    enter image description here

    There is no issue with your expression. Cross check whether the table name from the generated query exists or not in your source database.

    You can check the generated query from the expression in the copy activity input.

    enter image description here

    UPDATE:

    To copy the Policy data to new table PolicyV2, you can use dataset parameters. Create two datasets in which one for the source and another for the target. Add your source dataset to the copy activity source and give your first expression to get the data from dbo.Policy.

    @concat('SELECT * FROM ', pipeline().parameters.Domain,'.', pipeline().parameters.TableName)
    

    enter image description here

    In the target dataset, create two parameters of type strings.

    enter image description here

    Now, use these two parameters for the schema and table of the dataset as shown below.

    enter image description here

    Add this as copy activity sink and provide your Domain parameter to schema and for the table name give the below expression.

    @concat(pipeline().parameters.TableName,'V2')
    

    As you don't have target table, click on Auto create table option. This will auto create the table PolicyV2.

    enter image description here