CREATE PROCEDURE DBO.FindLostField (@master_db varchar(50), @source_db varchar(50), @cols varchar(200)) AS
SET NOCOUNT ON 

DECLARE @SQL VARCHAR(8000)

IF EXISTS(SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = 'findFieldMaster') 
  DROP TABLE findFieldMaster
IF EXISTS(SELECT name FROM sysobjects WITH (NOLOCK) WHERE name = 'findFieldSource') 
  DROP TABLE findFieldSource

SET @SQL = 'SELECT [' + @master_db + ']..sysobjects.name as Tablename, [' + @master_db + ']..syscolumns.name as ColName INTO findFieldmaster FROM [' + @master_db + ']..syscolumns WITH (NOLOCK) INNER JOIN [' + @master_db + ']..sysobjects WITH (NOLOCK)   ON [' + @master_db + ']..sysobjects.id = [' + @master_db + ']..syscolumns.id where [' + @master_db + ']..syscolumns.name in (''' + @cols + ''') order by [' + @master_db + ']..syscolumns.name'
EXEC (@SQL)

SET @SQL = 'SELECT [' + @source_db + ']..sysobjects.name as Tablename, [' + @source_db + ']..syscolumns.name as ColName INTO findFieldSource FROM [' + @source_db + ']..syscolumns WITH (NOLOCK) INNER JOIN [' + @source_db + ']..sysobjects WITH (NOLOCK)   ON [' + @source_db + ']..sysobjects.id = [' + @source_db + ']..syscolumns.id where [' + @source_db + ']..syscolumns.name in (''' + @cols + ''') order by [' + @source_db + ']..syscolumns.name'
EXEC (@SQL)


select * from findFieldMaster
where tablename+colname not in (
  select tablename+colname from findFieldSource WITH (nolock)
)

drop table findFieldMaster
drop table findFieldSource

