我將數據選擇到臨時表中,然後查詢該表以獲取報表的其他值。這裏是產生錯誤的代碼,如果它有什麼區別,臨時表中就有大約3600萬條記錄。它表示錯誤出現在第一個查詢的第一列。將表達式轉換爲數據類型的算術溢出錯誤int
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'
是什麼讓你覺得有一個轉換爲'int'?也許你應該包含錯誤信息。 – wallyk 2012-07-06 18:19:11
@wallyk - 這是我對這個錯誤感到困惑的部分。我看不出爲什麼它會將任何東西轉換爲int,特別是在該列上。 – RageQwit 2012-07-06 18:20:05
讓我們看看'create table#temp1'的語句和錯誤消息。 – wallyk 2012-07-06 18:21:27