【发布时间】:2026-02-04 17:00:01
【问题描述】:
我有一个 SQL 查询,我必须在 SQL Server Management Studio 中针对多 (15) 个表运行。
是否可以将多个查询的结果保存到一个文件中? (.txt、excel 表格?)
无法使用union,因为并非所有表都有相同数量的列。
查询看起来有点像这样
select *
from tableA
where main_id in (select id from maintable where date is null and status ='new')
select *
from tableB
where main_id in (select id from maintable where date is null and status ='new')
select *
from tableC
where main_id in (select id from maintable where date is null and status ='new')
select *
from tableD
where main_id in (select id from maintable where date is null and status ='new')
select *
from tableE
where main_id in (select id from maintable where date is null and status ='new')
【问题讨论】:
-
您使用的是哪个 dbms? (ANSI SQL 对文件一无所知。)
-
我在 MS sql server 中运行查询
-
我没有使用命令提示符。
-
你在使用 SSMS 吗?
标签: sql-server ssms