How can I avoid duplicate using the provided below query
INSERT INTO dbo.Entities(EntityId, [Name], [Description], [Type], Source)
SELECT DISTINCT
CUST_CODE, NAME, FULLDESCRIPTION, 'Agency' AS Type, 'SunDbAgencies' AS Source
FROM dbo.VW_SUNDB_AGENCIES
I've already tried all the answers here :
Avoid duplicates in INSERT INTO SELECT query in SQL Server to no avail.
The duplicates are in the dbo.VW_SUNDB_AGENCIES TABLES
not the INSERT
table, So I gather I need a way to remove duplicate from the select before inserting
Here is one of the duplicates which is why a simple distinct doesn't work: