I am开发者_JAVA百科 trying to write a stored procedure for SQL Server 2008. It is for a migration tool that migrates data from one database to another.
I want to get all records from the old database that aren't yet present in the new database. For that end I use the stored procedure below. But I get the error
The multi-part indentifier could not be bound
while executing the stored procedure. What can I do to make this work?
Here is the SP:
SELECT *
FROM Measurement_device
WHERE Measurement_device.Department_Code = '99'
AND mir.dbo.Gages.Gage_code != Device_Number
It's because you have the mir.dbo.Gages.Gage_code
condition when that table is not referenced in the FROM clause. Try something like this:
SELECT m.*
FROM Measurement_device m
LEFT JOIN mir.dbo.Gages g ON g.Gage_code = m.Device_Number
WHERE m.Department_Code = '99'
AND g.Gage_code IS NULL -- where the gage_code/device_number does not already exist in mir database
精彩评论