The following query is producing duplicate entries. Any idea what the culprit might be?
Here's some context: Basically, I have a table of data (called "trp"), and a couple of other tables with percentages in them. I have two queries...one if trp.DataType = "TRP" and another if trp.DataType = "OtherMetric". (The headers are all the same, but the calculation in the "Variable Value" column will be different for each of these queries.)
Code:
SELECT prc.Market AS Geography, trp.Product, trp.Indication, trp.[Variable Name], CStr(Format([trp.Period],"MM/DD/YYYY")) AS Period, prc.Index*trp.[Variable Value] AS [Variable Value], trp.Outlet, trp.Daypart, trp.[Program Name], trp.[LEN], trp.Creative, trp.Campaign, trp.[Campaign Name], trp.[Media Type], trp.Vendor, trp.Channel
FROM Nov2013_TVNational AS trp, tblTRPpercent AS prc
WHERE trp.Indication=prc.Indication AND trp.[Media Type]=prc.Type AND trp.Geography="National" AND trp.Month=prc.Month AND trp.DataType = "TRP"
UNION ALL SELECT prct.DMA AS Geography, trp.Product, trp.Indication, trp.[Variable Name], CStr(Format([trp.Period],"MM/DD/YYYY")) AS Period, prct.[percentUniverse]*trp.[Variable Value] AS [Variable Value], trp.Outlet, trp.Daypart, trp.[Program Name], trp.[LEN], trp.Creative, trp.Campaign, trp.[Campaign Name], trp.[Media Type], trp.Vendor, trp.Channel
FROM Nov2013_TVNational AS trp, tblDMApercent AS prct
WHERE (((trp.DataType)="OtherMetric"));