我有一堆非常简单的SELECT
语句。我想将它们全部输出到相同的结果集(UI表或文件)。这是我尝试过的最新事情:
@export on;
@export set filename="c:\test.csv";
@export set CsvColumnDelimiter=",";
SELECT TOP 1 * FROM TableName WHERE ID = 1;
SELECT TOP 1 * FROM TableName WHERE ID = 2;
SELECT TOP 1 * FROM TableName WHERE ID = 3;
SELECT TOP 1 * FROM TableName WHERE ID = 4;
SELECT TOP 1 * FROM TableName WHERE ID = 5;
@export off;
显然,CSV文件只包含ID 5,因为它只是覆盖。有没有办法追加?或者,在DBVis之外是否有任何SQL
选项允许我将所有这些SQL查询执行到一个结果集中?
答案 0 :(得分:2)
实现此目的的一种方法是使用UNION ALL返回一个结果集。
SELECT TOP 1 * FROM TableName WHERE ID = 1
UNION ALL
SELECT TOP 1 * FROM TableName WHERE ID = 2
UNION ALL
SELECT TOP 1 * FROM TableName WHERE ID = 3
UNION ALL
SELECT TOP 1 * FROM TableName WHERE ID = 4
UNION ALL
SELECT TOP 1 * FROM TableName WHERE ID = 5;
答案 1 :(得分:2)
@export on;
@export set filename="<outputfile.csv>" appendfile="true";
select * from tab;
@export set CsvIncludeColumnHeader="false";
select * from tab;
select * from tab;
这将导出包含列标题的第一个结果集和不带列标题的以下结果集。
答案 2 :(得分:0)
在IQ数据库中,客户端可以设置选项
set option isql_show_multiple_result_sets = 'on';
2个问题: