Question

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.

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. 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. 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.

Here is a picture, with a small arrow and text box to highlight the area which I (99% sure) believe is causing the problem. 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)

My issue

*All my Access DB's are set to accept Standard T-SQL syntax, so I will also tag this as T-SQL

Was it helpful?

Solution

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. 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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top