I am trying to prevent duplicates when I'm inserting values from a staging table into the primary table. I only have two components: an OLE DB SOURCE
which points to an OLE DB DESTINATION
.
In the OLE DB SOURCE
, I originally had this:
SELECT [QVW Names] as 'QVW Name', '1' as 'QVW Type'
FROM dbo.STG_QVD_Generator
WHERE [QVW Names] <> ''
UNION
SELECT [QVW Names] as 'QVW Name', '2' as 'QVW Type'
FROM dbo.STG_Data_Models
WHERE [QVW Names] <> ''
To prevent the duplicates, I researched and began testing out a new query by using SQL Server Management Studio, I was able to get this:
MERGE INTO QVW_Files AS tbl
USING (SELECT [QVW Names] as 'QVW Name', '1' as 'QVW Type'
FROM dbo.STG_QVD_Generator
WHERE [QVW Names] <> ''
UNION
SELECT [QVW Names] as 'QVW Name', '2' as 'QVW Type'
FROM dbo.STG_Data_Models
WHERE [QVW Names] <> '') AS src
ON (tbl.QVW_Name = src.[QVW Name] AND tbl.QVW_Type_ID = src.[QVW Type])
WHEN NOT MATCHED THEN
INSERT (QVW_Name, QVW_Type_ID)
VALUES (src.[QVW Name], src.[QVW Type]);
and it seems to prevent duplicates from being entered into the target tables from the staging tables. However, I entered this into my OLE DB SOURCE
and I realized that it would return no columns because this is not really a SELECT statement. How can I incorporate it into my Data Flow Task?
Thanks.