我正在尝试将两列合并为一列,其中一列具有空值。它看起来像这样:
| Order Number | MOP | MOP2 |
| 12345 | Cash | |
| 12346 | Credit | |
| 12347 | Visa | Cash |
| 12348 | Credit | |
我正在运行的查询如下所示:
Select
ORDER.OrderHistory.OrderNo
,ORDER.OrderHistory.MOP
,ORDER.OrderHistory.MOP2
From
ORDER.OrderHistory
我试图让它看起来像这样:
| Order Number | MOP |
| 12345 | Cash |
| 12346 | Credit |
| 12347 | Visa |
| 12347 | Cash |
| 12348 | Credit |
答案 0 :(得分:2)
只需将union
两列放入数据集中的同一列:
-- This query will return all your data rows
select o.OrderNo
,o.MOP
from ORDER.OrderHistory as o
union all
-- And then this one will get all where the MOP2 column is not null
select o.OrderNo
,o.MOP2
from ORDER.OrderHistory as o
where o.MOP2 is not null