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

excel, export-to-excel, sql-server

Solution

right click EXCEL column header

- go to Table => external table properties

- Uncheck `"Preserve column sort/filter/layout"`

- Refresh Excel

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.

Problem

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: From Excel: How can I get the column order to be the same in Excel as it is in SSMS?

Original source