SQL - 添加一个空行

SQL - Adding a blank row

我正在处理将使用我正在构建的查询从数据库中获取数据的软件。问题是软件没有判断table大小的工具,所以我需要在最后一行数据后加一个空行,这样软件才能识别table的结尾. 这是查询将给出的示例:

下面是我需要从查询中获取的示例:

我知道在应用程序中解决它会更好,但在这种情况下我需要更改我的查询。可能吗?

编辑:我正在使用 SQL Server 2014,数据库名称是 Test,table 名称是 Table2。

一个简单的方法是:

select t.*
from t
union all
select t.*
from (select 1 as x) x left join
     t
     on 1 = 0   -- always fails
order by (case when fieldA is not null then 1 else 2 end)

这 returns 多了一行,所有列都是 NULL

注意:SQL 表表示 无序 集合,因此您需要一个 order by。以上假设第一列永远不会 NULL.

在查询后使用 UNION ALL 添加空白行:

select t.* from (
  select FieldA, FieldB
  from Table2
  ..........
  union all
  select null, null 
) t
order by case when coalesce(t.FieldA, t.FieldB) is null then 1 else 0 end

或:

select t.FieldA, t.FieldB from (
  select 0 as isblankrow, FieldA, FieldB
  from Table2
  ..........
  union all
  select 1, null, null 
) t
order by isblankrow

我在 dbfiddle 上为 SQL Server 2014 提供了完整的解决方案。 dbfiddlelink

查询应该是,

Select * 
from (select FieldA,FieldB 
      from Table2 
      union
      select null,null) tab 
 order by FieldA Desc