Order Columns in output SQL table from Data flow

Walter Pelowski 76 Reputation points
2022-07-07T04:32:08.197+00:00

Is there any way to get columns to sort alphabetically in a Data flow for the Sink? Or specify some custom-sort order via a Select schema modifier operation in a Data flow prior to the Sink?

I would like this to be dynamic for whatever source table I pass into the Data flow via the parameters that have been established.

I've looked everywhere for something like this but can't seem to find anything.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2022-07-07T20:09:17.843+00:00

    Hello @Walter Pelowski ,

    Thanks for the question and using MS Q&A platform.

    My understanding is that you have a SQL source, and you would like to specify the source column order in ascending order and map to respective sink in mapping data flows. And you would like to have this as dynamic for any give source table as a parameter. Please correct me if my understanding is wrong.

    I don't think we have an out of box feature in ADF to achieve this but if your source is SQL then you can use the below query or create a stored procedure out of it and use it in your Mapping data flow source to pull the table schema in an ascending order by passing the table name parameter as a variable to your stored procedure.

    DECLARE @QUERY VARCHAR(2000)  
    DECLARE @TABLENAME VARCHAR(50) = 'EMPLOYEE'  
      
    SET @QUERY = 'SELECT '  
    SELECT @QUERY = @QUERY + Column_name + ',   
    '  
      FROM INFORMATION_SCHEMA.COLUMNS   
     WHERE TABLE_NAME = @TABLENAME  
     ORDER BY Column_name  
      
    SET @QUERY =  LEFT(@QUERY, LEN(@QUERY) - 4) + '   
    FROM '+ @TABLENAME  
      
    PRINT @QUERY  
    EXEC(@QUERY)  
    

    Here is the output looks like:

    218708-image.png

    Hope this helps. In case if your ask different than my understanding, please help clarify a bit with an example so that we can better assist you accordingly.

    Thank you


  2. Walter Pelowski 76 Reputation points
    2022-07-14T14:21:37.323+00:00

    Thanks. Yeah, it works. I was hoping to do the column ordering in the Data flow but instead I sink it to a DEV table and then immediately follow it up with an INSERT INTO script activity that orders the columns the way I want them. Here is what the pipeline looks like now.

    Thank you again.


Your answer

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