2015-08-20 74 views
0

獲取有關該代碼的第1行的錯誤...將表達式轉換爲數據類型int的算術溢出錯誤?

Select COUNT(MEM_REL) As MemberSub, CLM_CC2 As GroupNum 
From Impact.dbo.tbl_mem, Impact.dbo.tbl_clm 
Where MEM_REL = '01' 
Group by CLM_CC2 

的錯誤是:

MSg 8815, Level 16, State 2, Line 1 
Arithmetic overflow error converting expression to data type int 
+0

監守你逝去'MEM_REL =「01''你必須通過'MEM_REL = 1' – wiretext

+0

你在你的'FROM'缺少'JOIN'條款。 –

+0

我在哪裏加入@GordonLinoff? – AnalystSupreme

回答

2

嘗試引入正確的關係查詢,現在你得到的笛卡爾乘積兩張桌子。例如,用逗號,來代替逗號,,使用關鍵字JOIN來連接兩個表,然後定義您想要連接這些表的列的關係。

一旦你完成上面的返回值將大大減少的行數和下面的查詢可以正常工作,如果你有超過22個十億行下面的查詢,那麼你可能需要使用COUNT_BIG()功能,而不只是COUNT()

Select COUNT(MEM_REL) As MemberSub 
    , CLM_CC2 As GroupNum 
From Impact.dbo.tbl_mem 
INNER JOIN Impact.dbo.tbl_clm 
ON dbo.tbl_mem.[ReferencingColumn] = dbo.tbl_clm.[ReferencingColumn] 
Where MEM_REL = '01' 
Group by CLM_CC2 

查詢與COUNT_BIG()

Select COUNT_BIG(MEM_REL) As MemberSub 
    , CLM_CC2 As GroupNum 
From Impact.dbo.tbl_mem 
INNER JOIN Impact.dbo.tbl_clm 
ON dbo.tbl_mem.[ReferencingColumn] = dbo.tbl_clm.[ReferencingColumn] 
Where MEM_REL = '01' 
Group by CLM_CC2 
相關問題