I have two nearly identical tables, but for a difference of about 100 rows (out of 150k). I know how to find all the rows that exist in one table but not the other by using
SELECT [Column]
FROM [DB].[dbo].[Table_1]
WHERE NOT EXISTS
(SELECT *
FROM [DB].[dbo].[Table_1a]
WHERE [EDB].[dbo].[Table_1a].[Column] = [DB].[dbo].[Table_1].[Column])
But I want to be able to insert the rows missing from Table_1
into Table_1a
, but the above code doesn't work in an insert statement:
INSERT [DB].[dbo].[Table_1]
SELECT *
FROM [DB].[dbo].[Table_1a]
WHERE NOT EXISTS
(SELECT *
FROM [DB].[dbo].[Table_1a]
WHERE [DB].[dbo].[Table_1a].[Column] = [DB].[dbo].[Table_1].[Column])
As I get the error: The multi-part identifier "DB.dbo.Table_1.Column" could not be bound.
I have looked into that error from The multi-part identifier could not be bound and http://www.sql-server-helper.com/error-messages/msg-4104.aspx but neither of those solve my problem as I am not using JOIN
or aliases. So, I am not particularly sure what to do.
I am using SQL Server 2017.