命名多个结果集,以便我知道每个结果集

时间:2017-05-09 22:56:50

标签: sql-server sql-server-2008-r2

我一次运行几个SQL语句,给我几个结果集。有没有办法命名结果集,所以我知道它们是什么?

1 个答案:

答案 0 :(得分:2)

一种方法是添加名称为

的列
SELECT 'ResultSet1' AS name,
      1 AS c
FROM  (SELECT 1 UNION SELECT 2) AS sub(c)

SELECT 'ResultSet2' AS name,
      2 AS d;

SELECT 'ResultSet3' AS name,
      3 AS e;

<强> Rextester Demo