我正在将数据选择到临时表中,然后查询该表以获取报告的其他值。这是产生错误的代码,如果它有任何区别,那么临时表中大约有 3600 万条记录。它说错误出现在第一个查询的第一列。
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
这是临时表的语句(很丑)。错误消息是该线程的标题。
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'