I m in a situation where i need to compare two tables against Projectnumber. Both tables has field ProjectNumber but one has datatype INT and other has VARCHAR(45). So when i try to run following query it result some un-matched records too
Select prj.Projectnumber,ps.ProjectNumber as 'ProjectNumber2'
from projectlistsearch ps
inner join project prj on ps.ProjectNumber= prj.ProjectNumber
This result some correct records but also result bad like this
ProjectNumber ProjectNumber2
8 08-809076
11 11-437881
11 11-505934
2007 2007-45750
2011 2011-0A76
I tried type casting as well but did not work.
How can i overcome this situation to get only completely matched record?
thanks
I’d advise to convert the
INTtoVARCHARand compare those two, because for example converting aVARCHARtoINTwhen the text begins with decimal numbers, only the parseable prefix part will be converted to int:Input:
Parseable prefix:
Converted to
INTThe other way round, the
VARCHARvalue'8'is compared against'08-809076'which will not match.