-1

My query is how to update an SQL Server table from an Excel file where the Excel file contains multiple records for the same key with different timestamps. SO everytime I get this file, the query should only pick the latest timestamp and update the existing record in SQL Server with those details.

Should it be like sort in descending order in Excel, remove duplicates then update to SQL Server? Should all this be done in a VBA macro?

Kindly let me know how this can be done.

With regards, Manus

Community
  • 1
  • 1
Manus
  • 869
  • 2
  • 10
  • 20
  • Hi, SO is for where you have a specific coding related issue. Have a go at creating the macro yourself and let us know if there is a specific issue with the code. – Gareth Apr 13 '15 at 15:32

1 Answers1

0

You could load the Excel rows to a stage table . write a query partitioning by key and order by timestamp desc and only use the rows with row_number 1 to update rows in table.

Harsha
  • 31
  • 4
  • Hi Harsha, do you mean something like what is mentioned in this post? http://stackoverflow.com/questions/7747327/sql-rank-versus-row-number – Manus Apr 13 '15 at 15:54