SELECT *
FROM dbo.MainTable mt
LEFT JOIN Lookup_Items msn ON mt.Item = msn.Item_ID
WHERE msn.Item_ID is NULL
I have the above query that i want to use to find all rows in "MainTable" with out a matching foreign key.
Column Item in "MainTable" is of nvarchar(200) datatype but column Item_ID in table Lookup_Items is an int.
The problem i have is that if a row in MainTable does NOT have a matching foreign key, the Item column will contain string data and the above query will fail with error message
Conversion failed when converting the nvarchar value 'TestValue' to data type int.
Is there away i can work a round this so the query can execute successfully and still give me all rows with no matching foreign key?
Aucun commentaire:
Enregistrer un commentaire