0

我正在将数据选择到临时表中,然后查询该表以获取报告的其他值。这是产生错误的代码,如果它有任何区别,那么临时表中大约有 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'
4

2 回答 2

1

嗯,订阅别名在一个有 3400 万行的表中有 5 个左右不同的值。好吧,其中之一将至少有 600 万行。自连接将在此生成至少 36 万亿行,这很快就会在第二个查询中出现算术溢出。

你真的是这个意思吗?

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

这实质上是将计数的行数平方。我猜错误在第二个子查询中;位置报告不正确。

于 2012-07-06T18:35:53.170 回答
0

是否有可能您JOIN_DTM的日期无效(超出范围或仅为空)然后 DATEDIFF 运行它,将其转换为 int 并导致错误?

于 2012-07-06T18:23:26.927 回答