Microsoft Access 2003 SQL问题

时间:2010-02-11 18:00:41

标签: sql ms-access null union

我需要将几个表与Microsoft Access中的不同结构联合起来。

例如我有桌子:

table1 (column_a,column_b,column_c),
table2 (column_a,column_c),
table3 (column_d)

SQL如下所示:

SELECT table1 column_a,column_b,column_c, Null as column_d FROM Table1
UNION
SELECT table2 column_a,Null as column_b, column_c, Null as column_d FROM Table2
UNION
SELECT table3 column_a, Null as column_b, Null as column_c, Null as column_d 
FROM Table3;

但有时MS Access会显示有关不兼容类型的错误消息。

我认为这是因为在一个SELECT中生成的具有空值的列具有与另一个SELECT中相应的非自动生成的列不兼容的类型

是否可以使用null指定自动生成列的类型?

1 个答案:

答案 0 :(得分:0)

如何用空字符串('')替换Null?

如,

SELECT col_a, col_b,       col_c,       '' as col_d FROM Table1
UNION
SELECT col_a, '' as col_b, col_c,       '' as col_d FROM Table2
UNION
SELECT col_a, '' as col_b, '' as col_c, '' as col_d FROM Table3;