This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).
Insert into tragetDB.dbo.L_Building(building) Select building from sourceDB.dbo.L_Building CREATE TABLE #L_Building ( building [nvarchar](25) PRIMARY KEY NOT NULL) Insert into #L_Building (building) Select building FROM tragetDB.dbo.L_Building ---lets say I go through a set of many employee tables -- to extract building information one by one per table -- hence the loop below... SET @loop = @@ROWCOUNT WHILE (@loop <> 0) BEGIN SET @id = (SELECT autoid FROM #Employee WHERE autoid = @loop) IF (@id <> '' Or @id <> null) BEGIN .... SELECT @strSql = 'IF EXISTS ( SELECT DISTINCT (b.building) AS building FROM [' + @Employeesourcetable + '] AS b WHERE NOT EXISTS( SELECT 1 FROM L_Building as LB WHERE LB.building = (b.building) ) ) BEGIN INSERT INTO AI_DEV_Test.dbo.#L_building (b.building) FROM TargetDB.dbo.[' + @Employeesourcetable + '] AS b WHERE NOT EXISTS( SELECT 1 FROM L_Building as lb WHERE lb.building = (b.building) ) END' EXECUTE sp_executesql @strsql END SET @loop = @loop - 1 END