You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将多SELECT语句的T-SQL查询结果导入Excel的技术问询

Import Multiple T-SQL Result Sets into Excel (Matching SSMS Output)

Got it, let's walk through how to get those separate T-SQL result sets (each with different columns) into Excel exactly as they appear in SQL Server Management Studio. Since you're already starting with the Data > From Other Sources > From SQL Server workflow, here's how to tweak it to capture all your result sets intact:

Step 1: Complete the initial SQL Server connection setup

  • Navigate to Data > From Other Sources > From SQL Server in Excel.
  • Enter your server name, select your authentication method (Windows or SQL Server credentials), and pick the database where your query lives. Click Next.

Step 2: Paste your full multi-SELECT query

  • On the "Select Tables and Views" screen, skip picking pre-existing objects and look for the "Write a query" option (usually a button at the bottom of the window).
  • Paste your entire T-SQL query (all those separate SELECT statements) into the query editor box. Click Next to run it.

Step 3: Load all result sets (this is the critical part!)

  • Excel will automatically detect that your query returns multiple result sets, and you'll see a list of them labeled Table0, Table1, etc. (each corresponds to one of your SELECT statements in order).
  • Instead of clicking the default "Load" button (which only imports the first result set), click "Load To..." to customize the import:
    • Select all result sets in the list (hold Ctrl to pick individual ones, or Shift to select a range).
    • Choose your preferred destination:
      • New worksheet: Excel will create a separate tab for each result set, preserving their original order and column structure.
      • Existing worksheet: Specify a starting cell for each set if you want them all in one tab (but this can get messy with different column counts—separate worksheets are usually cleaner).
  • Click OK to start the import.

Quick Tip

If you ever accidentally click "Load" and only get the first result set, don't worry—just go back to the Queries & Connections pane (under the Data tab), find your query, right-click it, and select Load To... to pick the remaining result sets.

内容的提问来源于stack exchange,提问作者matandked

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:51:02