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
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.
TRUSTED BY