Power Automate Exchange

Please login or click SIGN UP FOR FREE to create your FlowUG account to join this user group.
 View Only
  • 1.  Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 12, 2020 01:13 PM
    Is there a faster way to get rows out of excel and into a SQL table (or viceversa) I have 8,000 rows by 9 columns and it took 20 minutes to "import" 3,000 rows.

    My flow steps are
    Excel:
    List Rows in a table (takes about 3 minutes)
    Apply to each value from the list rows object above
    Insert row for SQL

    my SQLtable is in an azure sql database

    ------------------------------
    Sam Duval
    Data Quality Analyst
    Element Financial
    Indianapolis IN
    ------------------------------


  • 2.  RE: Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 13, 2020 01:13 AM

    Indeed there is, but you're using the wrong tool.

    Have a look at Azure Data Factory. It's low code/no code and actually uses the same expression syntax as Logic Apps/Power Automate.

    A simple ETL process like pulling an Excel table and sinking it into Azure SQL won't take that long to get going in a simple copy pipeline and the processing time will go from 20 minutes to about 1 minute (once the compute cluster has been acquired which is approx 5 minutes).

    If you must use Flow, then you could construct a SQL query e.g.

    INSERT INTO YourTable ( intColumn, stringColumn ) VALUES( Value1, 'Value2' ), ( Value3, 'Value4' ) ..etc

    ..by append to string variable in an apply to each loop then put it in a SQL query step.

    But take the time to learn Azure Data Factory if you do this stuff a lot.



    ------------------------------
    Will Page
    Technical consultant
    Christchurch, NZ
    ------------------------------



  • 3.  RE: Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 13, 2020 07:16 AM
    Thanks @Will Page that's a good idea to use the string variable to construct the insert into query. I ended up reading the excel rows and creating a CSV table, then bulk insert the CSV into SQL (1 Column by 1 Row)​ and parsed the results via string split and another function I stole years ago off the internet to split into columns based on a delimiter.


    Took just over 3 minutes start to finish.

    We are looking at getting azure data factory, so that's something I'll have to look into. Is there anything Flow can do that azure data factory can't or flow does better? Looking to see if i should migrate flows to factory once we get it.

    ------------------------------
    Sam Duval
    Data Quality Analyst
    Element Financial
    Indianapolis IN
    ------------------------------



  • 4.  RE: Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 13, 2020 07:21 AM
    Until Power Automate supports bulk operations you are better off using proper ETL tools for this scenario.

    ------------------------------
    Lutz
    ------------------------------



  • 5.  RE: Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 13, 2020 07:27 AM
    Edited by Sam Duval Aug 13, 2020 07:27 AM
    Thanks @Lutz Bendlin. That's what i figured. We are getting azure data factory at some point, we were just stuck using the tools available while the IT department who does the majority of ETL reviewed the options for what they wanted to purchase for use by my department.​

    ------------------------------
    Sam Duval
    Data Quality Analyst
    Element Financial
    Indianapolis IN
    ------------------------------



  • 6.  RE: Insert Row (V2) To SQL Table

    Gold Contributor
    Posted Aug 14, 2020 06:50 AM
    @Sam Duval, just to add up on what others have said, Excel workbooks store data in a compressed format. When pulling data from an Excel workbook​, the workbook is first uncompressed and that is certainly what takes the most time, and usually a lot of memory. Passing by a CSV is better as the format is uncompressed and the data is readily available.​ Also, by definition, a CSV file will be bigger than an Excel workbook.
    @Will Page's suggestion of using Azure Data Factory is certainly the best way to go. ADF has some templates available to get you started with a simple Copy Pipeline and easy connection with your Azure SQL Database (and always store your connection credential using Azure Key Vault ;) ).

    All the best


    ------------------------------
    David Gerard
    Business Intelligence Consultant
    Kampala
    ------------------------------



  • 7.  RE: Insert Row (V2) To SQL Table

    Top Contributor
    Posted Aug 14, 2020 08:39 AM
    Thanks @David Gerard. My company is looking at getting ADF setup. As for the compression, I fully understand that and wasn't surprised by the 3 minutes to read the excel. It was then the 20 minutes to only do 3000 rows to SQL that was surprisingly slow, since the data was already "in memory" as an array within the flow. But sounds like that's do to the lack of bulk operations. ​I'm stuck in this case with using an excel file, because I need people to be able to actively update the file, then at night I sync the days work back to SQL.

    In this case the reading excel into an array and creating a csv table, and uploading the CSV file into SQL works very well. There is a 1000 limit on the number of insert into values within SQL, you could by-pass this with:

    INSERT
    INTO TableName( Colum1) VALUES (1)
    INSERT INTO TableName( Colum1) VALUES (2)
    INSERT INTO TableName( Colum1) VALUES (3)

    This is the column splitter code i'm using, combined with azure's string_split for converting line breaks (char(10)) into new rows

    declare @data as nvarchar(max)
    set @data = (select top 1 column1 from table)
    select [dbo].[UFN_SEPARATES_COLUMNS](value,1,',') Column1, dbo].[UFN_SEPARATES_COLUMNS](value,2,',') from sting_split(@data,char(10))

    function code:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER FUNCTION [dbo].[UFN_SEPARATES_COLUMNS](
     @TEXT      varchar(8000)
    ,@COLUMN    tinyint
    ,@SEPARATOR char(1)
    )RETURNS varchar(8000)
    AS
      BEGIN
           DECLARE @POS_START  int = 1
           DECLARE @POS_END    int = CHARINDEX(@SEPARATOR, @TEXT, @POS_START)
           WHILE (@COLUMN >1 AND @POS_END> 0)
             BEGIN
                 SET @POS_START = @POS_END + 1
                 SET @POS_END = CHARINDEX(@SEPARATOR, @TEXT, @POS_START)
                 SET @COLUMN = @COLUMN - 1
             END
           IF @COLUMN > 1  SET @POS_START = LEN(@TEXT) + 1
           IF @POS_END = 0 SET @POS_END = LEN(@TEXT) + 1
           RETURN SUBSTRING (@TEXT, @POS_START, @POS_END - @POS_START)
      END

    ​​​​

    ------------------------------
    Sam Duval
    Data Quality Analyst
    Element Financial
    Indianapolis IN
    ------------------------------



  • 8.  RE: Insert Row (V2) To SQL Table

    Posted Oct 10, 2022 04:34 PM
    If anyone still wants to do something like this with Power automate, you can try this batch SQL template: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/SQL-Batch-Create-Read-Update-and-Delete/td-p/1715338

    ------------------------------
    Tyler Kolota
    Power Platform Developer
    ------------------------------