简体   繁体   English

MS Access SQL子查询中的数据类型不匹配

[英]Data type mismatch in MS Access SQL sub-query

Alright, this query will not run and returns a data type mismatch error. 好的,此查询将不会运行,并返回数据类型不匹配错误。 This error did not start until I attempted to join two tables within the sub-query in the WHERE clause. 直到我尝试在WHERE子句中的子查询中联接两个表时,该错误才开始。

The two tables I am attempting to join are the exact two tables that are joined in the primary query. 我尝试连接的两个表正是在主查询中连接的两个表。 Each table contains a column, CRD Number. 每个表都包含一列CRD号。 In one table, it is stored as text, in the other, it is stored as number. 在一个表中,它存储为文本,在另一个表中,存储为数字。 This is why I have used the CStr() function to cast the numerical column as a textual column. 这就是为什么我使用CStr()函数将数字列转换为文本列的原因。 This worked beautifully for the primary query (thank Stack Overflow!) but when I attempted to do the same exact join in the sub-query, I received the data type mismatch error. 这对于主查询非常有效(感谢Stack Overflow!),但是当我尝试在子查询中执行相同的完全连接时,我收到了数据类型不匹配错误。

Here is a picture, with a small arrow and text box to highlight the area which I (99% sure) believe is causing the problem. 这是一张图片,上面有一个小箭头和文本框,以突出显示我(确定为99%)认为引起问题的区域。 Again, the problem only arose when I attempted to join these two tables in the sub-query. 同样,仅当我尝试在子查询中联接这两个表时才出现问题。 If the join is removed, the query will run. 如果删除了该联接,则查询将运行。 (Although the sub-query will not return the correct results, thus making my primary query useless) (尽管子查询将不会返回正确的结果,从而使我的主查​​询无用)

我的问题

*All my Access DB's are set to accept Standard T-SQL syntax, so I will also tag this as T-SQL *我所有的Access DB都设置为接受标准T-SQL语法,因此我也将其标记为T-SQL

I think the difference is probably that in the primary query you are excluding the cases where Crd Number is null, but in the subquery you are not. 我认为差异可能是在主查询中您排除了Crd Number为null的情况,但在子查询中却没有。 I don't have Access installed to be able to test, but I would bet it will work if you add to the subquery where clause. 我没有安装Access才能进行测试,但是我敢打赌,如果您将它添加到子查询的where子句中,它将可以正常工作。

sp.CRD_NUMBER is not null and dtp.CRD_NUMBER is not null

I suspect that the function CStr() is having a problem with null values, but then again, I can't test this to see if that would make a difference. 我怀疑函数CStr()的null值有问题,但是再说一次,我无法测试它是否会有所作为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM