我有一行数据想要添加列,所以我交叉应用了一些数据。
但是,所应用的表有时为空。
当应用的表为null时,不会返回任何内容。
表1
| a | b | c |
|---+---+---|
| 0 | 1 | 1 |
表2
| d | e | f |
|---+---+---|
查询
select top 1
[col_1] = coalesce([a], [d], '')
from table_1
cross apply ( select [d], [e] from table_2)
预期输出
| a | b | c |
|---+---+---|
| 0 | 1 | 1 |
实际输出
*null*
交叉应用Table 1
时,无论数据是否可用,如何保留Table 2
中的列?
注意:我正在尝试结合使用。
使用outer apply
:
select top 1
[col_1] = coalesce([a], [d], '')
from table_1
outer apply ( select [d], [e] from table_2)