Msg 8115, Level 16, State 2, Line 2 Arithmetic overflow error converting expression to data type int - sql

I am getting an error after firing this query.
select COUNT(*)
from [DB1].dbo.Transaction(nolock) t
join [DB2].dbo.visits (nolock) v
on t.V_ID=v.V_ID
where t.Ct_ID=11
and t.Timestamp>'06-08-2015'
and v.C_ID is null
Error:
Msg 8115, Level 16, State 2, Line 2 Arithmetic overflow error converting expression to data type int

Try using COUNT_BIG instead of COUNT.
Read this article for more information. Additionally, this shows the limits for the different types of INTs.

Related

Simple conversion of SQL date field to mm/dd/yyy

I'm having a problem converting three columns to mm/dd/yyyy format in MS SQL Server.
There are a number of methods I've looked up here but nothing that quite worked when I tried to implement it. It's a very basic set of columns I'm pulling.
SELECT
[Incident_Number]
,[Corporate_ID]
,[Assignee_Login_ID]
,select *, cast ([Submit_Date] as date) <TIME_CREATED> from SERVICEMGMT where date = 'mm/dd/yyyy'
,[Last_Resolved_Date] as TIME_RESOLVED
,[Closed_Date] as TIME_CLOSED
,[Description]
FROM [SERVICEMGMT].[dbo].[Help_Desk]
Where (corporate_id LIKE ('b%') AND TEMPLATE_NAME = ('PC: Local Build/Deployment') AND STATUS > 3);
I'm getting a basic incorrect syntax error. The actual error messages are:
Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 6 Incorrect syntax near ','.

DELETING NULL ERROR MSG APPEARING

I am trying to delete away all the rows with NULL. I tried using the code:
DELETE FROM [FILENAME] WHERE [MONTH] = 'NULL'
But the error msg appears as:
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting
date and/or time from character string.
I'm guessing i have to convert something but got no clue. Any help will be great. thanks
The error is because (NULL) is not a value and not a string value to put it between two single quotation marks('').
NULLs have special ways and special functions to deal with it, so you can use this code to delete away all the rows with NULL
DELETE FROM [FILENAME] WHERE [MONTH] IS NULL

SQL Logarithmic Exponent Calculations Log(Exp(Today-FirstSeen/365))

I am attempting to calculate Log(exp(Today-(FirstTimeSeen/365))) using the code listed below.
When executing the query I receive the error message listed below.
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type float.
I have broken the query apart and determined that the error is related to the exp(getdate()) calculation.
select LOG(exp(cast(convert(float,getdate())-(convert(float,[FirstSeen])/365) AS DECIMAL (10,5)))) from FindingsByDate

Arithmetic overflow error converting expression to data type smallint

I am new to SQL Server, this question might be repeated here. Since i haven't find a solution for my problem. I wished to post here. So here is my problem
select(volume * speed) from traffic_data_replica;
I am trying to multiply values from two columns , data type is smallint for both columns. Error i got is :
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type smallint.
Cast one of the values to a "bigger" type before the calculation:
select cast(volume as int) * speed
from traffic_data_replica;
You can also do this easily by multiplying by 1.0:
select 1.0*volume*speed
from traffic_data_replica

SQL Case statement error Msg 8114

Trying to build a simple case statement using SQL Server 2008 and running across an issue giving me the following error message:
Msg 8114, Level 16, State 5, Line 6
Error converting data type varchar to numeric.
I've isolated the script causing the issue to the following:
CASE WHEN tPersonLocationHist.LocationCode = 'DC'
AND (tPersonJobHist.FullTimeEquivalent = 1)
AND (MONTH(tPersonStatusHist.LatestHireDate) < 10)
THEN tPersonStatusHist.NormalHoursPerWeek / 5
The tPersonStatusHist.NormalHoursPerWeek is formatted as decimal; however, I can't get it to calculate.
Any tips? The resulting calculation needs to be in decimal form (to two decimal digits).
Even if I change the THEN statement to just '7.5', it then returns:
Msg 245, Level 16, State 1, Line 6
Conversion failed when converting the varchar value '7.5' to data type int.
I've tried using CONVERT(decimal(4,2),tPersonJobHist.NormalHoursPerWeek * 7.5), but no luck on that either.
Only thing that's working is to do it as:
CONVERT(int,tPersonJobHist.NormalHoursPerWeek * 7.5), but then it is dropping the decimals and just giving the whole integer.
As you can probably tell, I'm new into SQL and still learning the rope, so any help you can give is much appreciated.
Are your other cases/else returning varchar? They should all return the same datatype. You may want to cast/convert them to be sure.
CAST(CONVERT(decimal(4,2),tPersonJobHist.NormalHoursPerWeek * 7.5) AS varchar(50))
First convert to decimal then do the division:
THEN CONVERT(decimal(4,2), tPersonStatusHist.NormalHoursPerWeek) / 5
Or cast is an option:
THEN CAST(tPersonStatusHist.NormalHoursPerWeek AS decimal(4,2)) / 5