if exists (select * from sys.syscolumns where name = 'ScanID' and id = object_id(N'dbo.InventoryADDomain'))
begin
    insert into InventoryScanADUser (ScanID, ADUserID) select d.ScanID, u.ID as ADUserID from InventoryADUser u inner join InventoryADDomain d on u.ADDomainID=d.ID;
    insert into InventoryScanADDomain (ScanID, ADDomainID) select ScanID, ID as ADDomainID from InventoryADDomain;
    alter table dbo.InventoryADDomain drop column ScanID;
end;