Search code examples
sql-serverexcelexport-to-excel

How do I import columns into Excel from SQL in the same order as they are in SQL Server?


I created a 'vwTable' view on SQL Server with the following column order:

Shift_id | Client_ip | Machine_Center

but when I select the view using "get external data" from Excel:

SELECT * FROM vwTable

The order of the columns in Excel is not the same; the output is:

Machine_Center | Client_ip | Shift_id

From SSMS:

enter image description here

From Excel:

enter image description here

How can I get the column order to be the same in Excel as it is in SSMS?


Solution

    1. right click EXCEL column header

      • go to Table => external table properties
      • Uncheck "Preserve column sort/filter/layout"
      • Refresh Excel
    2. right click Excel column header

      • go to Table => external table properties
      • check "Preserve column sort/filter/layout"
      • Refresh Excel

    The order of the columns in Excel are now the same order as they are in the SQL View.