Joining Two Tables with Different Data types MS ACCESS - 'type mismatch in expression' error

人走茶凉 提交于 2019-12-31 05:34:07

问题


I'm trying to run a query on access using two live CSVs which has a common field with different data types(numbers and short text). I've discovered that you can join different data types using 'CStr'. I've added the 'CStr' to my code on the sql view. Please find the see the code below.

This gives me the output i want on access and i can now see the output when i click on 'datasheet view'. However, when i try to export the data (i'm actually trying create a export specification so that i can export a csv using macro) as a csv i'm getting a 'type mismatch in expression' error message.

Here's my code:

SELECT Sixthform_Reg_Year_Groups.Forename, 
       Sixthform_Reg_Year_Groups.Surname, 
       Sixthform_Reg_Year_Groups.Reg, Students.objectGUID
FROM Sixthform_Reg_Year_Groups INNER JOIN
     Students
     ON CStr(Sixthform_Reg_Year_Groups.Person_id) = Students.employeeID
WHERE (((Sixthform_Reg_Year_Groups.Reg)="12E"));`

I've also tried adding 'CStr' on both sides. as below, but experiencing the same issue.

FROM Sixthform_Reg_Year_Groups INNER JOIN
     Students
     ON CStr(Sixthform_Reg_Year_Groups.Person_id) = CStr (Students.employeeID)
WHERE (((Sixthform_Reg_Year_Groups.Reg) = "12E"));`

And of course, without 'CStr' i can't even view the output on 'datasheet view'. Every time when i click on datasheet view it's giving me the 'type mismatch in expression' error message.

Any help in resolving this would be much appreciated.

Thanks in advance.

Additinal info: the data types are EmpoyeeID is 'Short Text' and Person ID is 'Number'


回答1:


OK guys, I've managed to resolve this issue, It turned out to be simple in the end. This is what i did.

Basically, I re imported the linked table. This time on the import window i clicked on 'advanced' and changed the data type to 'short text' on the 'person ID' column to match with the 'employeeID' data type. And then all problems solved. (I didn't know you could do this)

Thank you all for your replies. Going through your comments guided me to the right path.

Much appreciated.




回答2:


Try the other way round:

ON Sixthform_Reg_Year_Groups.Person_id = Val(Students.employeeID)

and/or prevent Null errors:

ON CStr(Nz(Sixthform_Reg_Year_Groups.Person_id, 0)) = Nz(Students.employeeID)


来源:https://stackoverflow.com/questions/52626744/joining-two-tables-with-different-data-types-ms-access-type-mismatch-in-expre

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!