【问题标题】:How do I import columns into Excel from SQL in the same order as they are in SQL Server?如何以与 SQL Server 中相同的顺序将列从 SQL 导入 Excel?
【发布时间】:2020-03-31 04:54:13
【问题描述】:

我在 SQL Server 上使用以下列顺序创建了一个“vwTable”视图:

Shift_id | Client_ip | Machine_Center

但是当我使用 Excel 中的“获取外部数据”选择视图时:

SELECT * FROM vwTable

Excel中列的顺序不一样;输出是:

Machine_Center | Client_ip | Shift_id

来自 SSMS:

来自 Excel:

如何让 Excel 中的列顺序与 SSMS 中的相同?

【问题讨论】:

    标签: sql-server excel export-to-excel


    【解决方案1】:
    1. 右键单击 EXCEL 列标题

      • 转到表 => 外部表属性
      • 取消选中"Preserve column sort/filter/layout"
      • 刷新 Excel
    2. 右键单击 Excel 列标题

      • 转到表 => 外部表属性
      • 检查"Preserve column sort/filter/layout"
      • 刷新 Excel

    Excel 中列的顺序现在与它们在 SQL 视图中的顺序相同。

    【讨论】:

      【解决方案2】:

      为什么不在你的选择中命名它们?

      Select Shift_id, Client_ip, Machine_Center from vwTable
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-27
        • 1970-01-01
        相关资源
        最近更新 更多