I'm selecting data into a temp table, then querying that table to get other values for a report. Here is the code that produces the error, and if it makes any difference there are about 36 million records in the temp table. It says the error is on the first column of the first query.
SELECT SUBSCRIPTION_ALIAS,
'Count' = 0,
COUNT(SUBSCRIPTION_ALIAS) AS MonthChange
FROM #Temp1 A WHERE DATEDIFF(day,JOIN_DTM,'01/01/2012') < 31
GROUP BY SUBSCRIPTION_ALIAS
UNION
SELECT B.SUBSCRIPTION_ALIAS,
COUNT(B.SBSCRPTN_MBR_KEY) AS [Count],
'MonthChange' = 0
FROM #Temp1 B JOIN #Temp1 A ON B.SUBSCRIPTION_ALIAS = A.SUBSCRIPTION_ALIAS
GROUP BY B.SUBSCRIPTION_ALIAS
DROP TABLE #Temp1
Here is the statement for the temp table (it's ugly). The error message is the title of this thread.
SELECT
bi_communications.F_EML_RCPNT.SBSCRPTN_LIST_KEY,
bi_communications.F_EML_RCPNT.SBSCRPTN_MBR_KEY,
bi_communications.D_SBSCRPTN_LIST.SBSCRPTN_LIST_NM,
bi_communications.F_EML_RCPNT.DLRY_DT_KEY,
bi_communications.D_DT.DT_DT,
CASE
WHEN D_SBSCRPTN_LIST.SBSCRPTN_LIST_NM = 'active-offers' THEN 'Special Offers'
WHEN D_SBSCRPTN_LIST.SBSCRPTN_LIST_NM = 'reserveamerica-offers' THEN 'RA Special Offers'
WHEN D_SBSCRPTN_LIST.SBSCRPTN_LIST_NM in
('active-team-sports-insider','active-tennis','active-women-news', ... (omitting excess)
) THEN 'Content'
WHEN D_SBSCRPTN_LIST.SBSCRPTN_LIST_NM = 'local-events' THEN 'Local Events'
ELSE 'Blank'
END AS SUBSCRIPTION_ALIAS,
bi_communications.D_SBSCRPTN_MBR.JOIN_DTM
INTO #Temp1
FROM bi_communications.F_EML_RCPNT
JOIN
bi_communications.D_SBSCRPTN_LIST ON bi_communications.F_EML_RCPNT.SBSCRPTN_LIST_KEY = bi_communications.D_SBSCRPTN_LIST.SBSCRPTN_LIST_KEY
JOIN bi_communications.D_DT ON bi_communications.F_EML_RCPNT.DLRY_DT_KEY = bi_communications.D_DT.DT_KEY
JOIN bi_communications.D_SBSCRPTN_MBR ON bi_communications.F_EML_RCPNT.SBSCRPTN_MBR_KEY = bi_communications.D_SBSCRPTN_MBR.SBSCRPTN_MBR_KEY
WHERE
bi_communications.F_EML_RCPNT.SBSCRPTN_LIST_KEY IN
( 180740437, 180741017, 180740482, 180740438, ... )
AND bi_communications.D_DT.DT_DT BETWEEN '01/01/2011 00:00:00' AND '01/01/2012 00:00:00'
int? Maybe you should include the error message.create table #temp1and the error message.