We are using Licensed version SQL Server Standard 2008 R2 of AWS.
We are upgrading our database from SQL 2008 R2 (10.50.1600.1) to SQL Server 2016 (13.0.16106.4).
After setting Compatibility level to 130, below query returns the below error.
Msg 8115, Level 16, State 2, Line 22 Arithmetic overflow error converting expression to data type int.
Both tables wfWorkflows & wfTasks have same column WorkflowId with same data type INT, NOT NULL.
declare @CompanyID int = 510, @RecordPkId int = 4551138,@zoneDifference varchar(6) = null
Select Minutes =
(
Select sum(isnull(TimeSpentOnTask,0))
from wfTasks With(nolock)
inner join comAdvisers With(nolock) on
comAdvisers.AdviserId = wfTasks.AdviserId
Where WorkflowId = wfWorkflows.WorkflowId
)
from wfWorkflows With(nolock)
Where companyid = @CompanyID
And ISNULL(ClientID,AdviserID) = @RecordPkId And ISNULL(InitSave,0) <> 1;
if i comment any single column from select then i will get no error, query works fine. With all column i get error. declare @CompanyID int = 510, @RecordPkId int = 4551138,@zoneDifference varchar(6) = null
Select Minutes = (Select sum(isnull(TimeSpentOnTask,0)) from wfTasks With(nolock) Where WorkflowId = wfWorkflows.WorkflowId),
EstMinutes = (Select sum(isnull(Duration,1)) from wfTasks With(nolock)
Where WorkflowId = wfWorkflows.WorkflowId)
from wfWorkflows With(nolock)
Where companyid = @CompanyID And ISNULL(ClientID,AdviserID) = @RecordPkId And ISNULL(InitSave,0) <> 1
intWITH (NOLOCK)means you are OK with reading dirty data. It meansdon't respect locks, notdon't take locks. This suggests that your query already has performance issues. Simplify your query, comment parts and bring them back one by one until you find which one causes the overlfow.TimeSpentOnTaskrequires a 64-bit integer