我正在处理一个错误'在我正在处理的SP中将表达式转换为数据类型int'的算术溢出错误。我提出了一个有问题的查询(其他查询也可能)。
我不确定是什么导致它。我唯一想到的是第11行的COUNT(不同的Sub_ID + Sub_Dep_Number。这个串联是两个字符串,但我认为它可能会尝试添加它们,因为它们可能是数字格式。
有什么想法吗?
由于
SELECT Distinct countSubs.[Number Dependents] AS [Number Dependents],
(AVG((YEAR(GETDATE())- Year(Individual.Sub_Dep_DOB)))) AS [Average Age], [Group_Base].Group_Base_Name,
Individual.State_Code, [Group_Base].BASE_GROUP_NO
, [Plan].Group_Address, [Plan].Group_City, [Plan].Group_State, [Plan].Group_ZIP
FROM Individual
INNER JOIN
Group_Base ON Individual.Group_Base = Group_Base.BASE_GROUP_NO
INNER JOIN
[Plan] ON [Group_Base].BASE_GROUP_NO = [Plan].BASE_GROUP_NO
INNER JOIN
(Select Distinct Individual.Group_Base,COUNT(Distinct (Sub_ID + Sub_Dep_Number)) [Number Dependents]
From Individual
Where State_Code = 'OH'
and Individual.Sub_Dep_Number <> '0'
AND ((Individual.Sub_Cancel_Indicator = 'false' AND Individual.Sub_Dep_Effective_DT <= '5/5/2013')
OR
(Individual.Sub_Cancel_Indicator = 'true' AND ((Sub_Dep_Cancel_DT BETWEEN '5/1/2013' AND '5/5/2013')
AND(Sub_Dep_Effective_DT <= '5/5/2013'))))
AND Individual.RegComp_SystemSource = 'Genelco'
AND (Individual.Benefit_Effective_DT != Individual.Benefit_Cancel_DT)
Group by Individual.Group_Base) as countSubs
ON (countSubs.Group_Base = [Group_Base].BASE_GROUP_NO)
--WHERE ((Individual.Sub_Cancel_Indicator = 'false' AND Individual.Benefit_Effective_DT <= '5/5/2013')
--OR
--(Individual.Sub_Cancel_Indicator = 'true' AND ((Benefit_Cancel_DT BETWEEN '5/1/2013' AND '5/5/2013')
--AND(Benefit_Effective_DT <= '5/5/2013'))
WHERE ((Individual.Sub_Cancel_Indicator = 'false' AND Individual.Sub_Dep_Effective_DT <= '5/5/2013')
OR
(Individual.Sub_Cancel_Indicator = 'true' AND ((Sub_Dep_Cancel_DT BETWEEN '5/1/2013' AND '5/5/2013')
AND(Sub_Dep_Effective_DT <= '5/5/2013'))
))
AND (Individual.Sub_Dep_Number <> '0')
AND (Year(Individual.Sub_Age)) >= '30'
AND (Individual.Benefit_Effective_DT != Individual.Benefit_Cancel_DT)
AND (Individual.State_Code = 'OH')
AND Individual.RegComp_SystemSource = 'Genelco'
GROUP BY [Group_Base].Group_Base_Name, [Number Dependents],
Individual.State_Code, [Group_Base].BASE_GROUP_NO
, [Plan].Group_Address, [Plan].Group_City, [Plan].Group_State, [Plan].Group_ZIP
答案 0 :(得分:0)
原来这个错误来自[Plan]表的Inner Join,我还是不太明白它但是我改变了Innerjoin有一个嵌套的select语句,它从中拉出地址。