I have the following query which works well. However, there are problems with the data and I need to remove the duplicate sVisitID's from the result. This is the SELECT I am using and the screenshot shows the result. I need to edit the select in order to only return one of the duplicates.
SELECT DISTINCT(MyReps.[sName]) as 'Rep Name', MyData.[sVisitID] as 'ID', CAST(MyData.[sDate] AS DATE) as 'Date', MyData.[sClientName] as 'Store Name', MyData.[sState] as 'Region', CAST(MyData.[sLatitudeStart] AS VARCHAR(100)) + ',' + CAST(MyData.[sLongitudeStart] as varchar(100)) as 'Map' FROM (SELECT * FROM [tblRepresentatives] WHERE [sActive] = 'True') as MyReps FULL OUTER JOIN (SELECT * FROM [tblVisits] WHERE CAST([sDate] AS DATE) = CAST(GETDATE()-1 AS DATE)) AS MyData ON MyReps.[sName] = MyData.[sRepresentativeName] WHERE MyData.[sClientName] IS NOT NULL AND [sDateAndTimeStart] <> [sDateAndTimeEnd] ORDER BY MyData.[sClientName] DESC Results:
