0

我在 Access 中有两个查询。它们两者的创建都比较讨厌,但在过程结束时,它们确实具有相同数量的具有相同数据类型的字段。他们都独立工作,产生预期的结果。

很遗憾,

SELECT * 
FROM [qry vaBaseQuery-S2]
UNION ALL SELECT *
FROM [qry BaseQuery];

一个接一个地抛出两个“无效使用 null”错误。我之前在 Access 2000 查询中使用过带有空值的 union 没有问题,所以我有点难过。谁能建议这里可能发生的事情?

可能相关的更多信息:

  • 两个查询都没有任何空白行

  • UNION SELECT *(没有 ALL)会抛出相同的错误,但只抛出一次?!

编辑:

  • 使用字段名称而不是 * 没有帮助

编辑2:

  • 鉴于查询将成为从表单运行的生成表查询,我只是将其保留为两个单独的查询(一个生成表和一个追加)并按顺序触发这两个查询。鉴于下面的答案,这听起来比尝试实际找出 Access 反对的内容要少得多。
4

3 回答 3

1

您很可能在源查询中有一些条件 (Iif()) 数据转换(CStr() 或类似的)。Access 可能会以不同于联合的方式优化单独的查询;有时它以非常奇怪的顺序评估条件部分。

就像在下一个过于简化的情况下:

Select Iif(int_fld is null, '0', CStr(int_fld)) As Something

这可能会抛出“无效使用 null” - 取决于评估顺序。

编辑:忘记写正确的表达式,它不会给出这个错误:

Select CStr(Iif(int_fld is null, 0, int_fld)) As Something
于 2009-06-08T12:29:52.213 回答
1

Arvo wrote: "sometimes [ACE/Jet] evaluates conditional parts in very weird order" -- I can vouch for that and not just when using UNION. Here's something I posted recently on SO where merely adding a WHERE clause to a query resulted in the engine evaluating in the wrong order causing an 'Invalid procedure call' error and I could not find a way round it.

SQL for parsing multi-line data?

I suggest you post the SQL code from the two Query objects. Perhaps someone can spot something the engine may have problems with.

于 2009-06-08T19:18:45.990 回答
0

As mentioned in edited question: Given the query was going to be a make table query run from a form anyway, I just left it as two separate queries (one make table and one append) and trigger the two in sequence.

于 2009-06-09T12:01:54.167 回答