Sql insert activity is not uploading data in correct order


I have data in excel sheet which I am reading in a datatable and then trying to insert into sql table on sql server. I can upload the data into sql table but the order of data rows in not correct to what I have in my datatable or in excel sheet.

I checked the order of rows in the input data of sql insert query which is correct but somehow it is inserting rows randomly in sql table. Any help in this regard?


Try using Insert Query as below Inside the for each loop

Insert into table name (Column1,Column2…)Values(’"+CurrentRow(0).Tostring+"’,"+CurrentRow(1).Tostring+"’…)



We can check this like

—once after the datatable been fetched from excel it will obviously have the same order of rows as in excel
But still let’s confirm that first with these two activities
—use a OUTPUT DATATABLE ACTIVITY and pass the dt variable as input and get the output as string variable named str_dt
—and then use a writeline activity and mention the str_dt as input
—now output panel will show the data and you can check the order of rows in it

And pls clarify how the data is inserted
Can we see the query if possible

Thanks for replying:)

I am not using any sql query command. I am using UIPath activity for it i.e. UiPath . Database . Activities . InsertDataTable. So, I am getting wrong order on my SQl table due to this activity.

Is it occurring for all the table or only for this table in database

Did we try manually once and check how it is inserting when done manually

Whilst it is odd for the data to not be in order, SQL tables shouldn’t rely on any kind of order. If you are needing your data to be in a specific order then I dare say you have bigger problems, perhaps you should reconsider your data structure. As long as all you data gets in I wouldn’t overthink it.

Yes, It occurs for more than one table.

I just want to be my data in the same order as I have in my datatable but I think, this is not the case with Sql as it does not maintain the same order of rows as you just said as per my understanding.

Yeah, I’m saying thats the wrong mindset to have, especially in a raw table.
SQL server is built upon the assumption you will design in with relational data principles in mind which do not require the data to be in any specific order.

If you aren’t familiar with relational database design I’d strongly urge you to take a step back before using SQL Server and have someone who knows that stuff to help you with your data.


Then it is something needs to be checked with sql database @WASEEM_KHAN
Pls check with database admin team

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.