I have a report that querys 5 data tables with unions and performs counts for each listkey. I runs fine in the Report designer "Execute Query". But when I run it in the report viewer if it has 23 rows it returns the report 23 times. Not sure from the above post how the repair? Please
SELECT
IPTReferralFromDropDown.ListValue,
1
AS
orderKey,
COUNT
(IPTAllStatsMain.ReferralFromKey)
AS
ReferralFrom
FROM
IPTReferralFromDropDown
INNER
JOIN
IPTAllStatsMain
ON
(IPTAllStatsMain.ReferralFromKey = IPTReferralFromDropDown.ListKey)
AND
year
(IPTAllStatsMain.CreatedOn) =
year
(getdate())
--IPTAllStatsMain.CreatedOn BETWEEN @startDate AND @endDate
GROUP
BY
IPTReferralFromDropDown.ListValue
UNION
--Caller Relation
SELECT
IPTCallerRelationDropDown.ListValue,
2
AS
orderKey,
COUNT
(IPTAllStatsMain.CallerRelationKey)
AS
CallerRelation
FROM
IPTCallerRelationDropDown
INNER
JOIN
IPTAllStatsMain
ON
(IPTAllStatsMain.CallerRelationKey = IPTCallerRelationDropDown.ListKey)
AND
year
(IPTAllStatsMain.CreatedOn) =
year
(getdate())
--IPTAllStatsMain.CreatedOn BETWEEN @startDate AND @endDate
GROUP
BY
IPTCallerRelationDropDown.ListValue
UNION
--Marital Status
SELECT
IPTMaritalStatusDropDown.ListValue,
3
AS
orderKey,
COUNT
(IPTAllStatsMain.MaritalStatusKey)
AS
MaritalStatus
FROM
IPTMaritalStatusDropDown
INNER
JOIN
IPTAllStatsMain
ON
(IPTAllStatsMain.MaritalStatusKey = IPTMaritalStatusDropDown.ListKey)
AND
year
(IPTAllStatsMain.CreatedOn) =
year
(getdate())
--IPTAllStatsMain.CreatedOn BETWEEN @startDate AND @endDate
GROUP
BY
IPTMaritalStatusDropDown.ListValue
UNION
--Ethnicity
SELECT
IPTEthnicityDropDown.ListValue,
4
AS
orderKey,
COUNT
(IPTAllStatsMain.EthnicityKey)
AS
Ethnicity
FROM
IPTEthnicityDropDown
INNER
JOIN
IPTAllStatsMain
ON
(IPTAllStatsMain.EthnicityKey = IPTEthnicityDropDown.ListKey)
AND
year
(IPTAllStatsMain.CreatedOn) =
year
(getdate())
--IPTAllStatsMain.CreatedOn BETWEEN @startDate AND @endDate
GROUP
BY
IPTEthnicityDropDown.ListValue
UNION
--Annual Income
SELECT
IPTAnnualIncomeDropDown.ListValue,
5
AS
orderKey,
COUNT
(IPTAllStatsMain.AnnualIncomeKey)
AS
AnnualIncome
FROM
IPTAnnualIncomeDropDown
INNER
JOIN
IPTAllStatsMain
ON
(IPTAllStatsMain.AnnualIncomeKey = IPTAnnualIncomeDropDown.ListKey)
AND
year
(IPTAllStatsMain.CreatedOn) =
year
(getdate())
--IPTAllStatsMain.CreatedOn BETWEEN @startDate AND @endDate
GROUP
BY
IPTAnnualIncomeDropDown.ListValue
ORDER
BY
orderKey