我正在处理的 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