Microsoft Access 2003 SQL 问题

发布于 2024-08-21 02:34:42 字数 602 浏览 5 评论 0原文

我需要在 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 的自动生成列的类型?

I need to union several tables with the different structure in Microsoft Access.

For example I have table:

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

SQL looks like follows:

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;

But sometimes MS Access shows the error message about incompatible types.

I think this because of generated columns with null values in one SELECT have the type incompatible with corresponding not autogenerated columns in another SELECT

Is there way to specify type of the autogenerated column with null?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

善良天后 2024-08-28 02:34:42

用空字符串 ('') 替换 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;

What about replacing the Null's with empty strings ('')?

e.g.,

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文