I'm getting this error
msg 8115, level 16, state 2, line 18
Arithmetic overflow error converting expression to data type int.
with this SQL query
DECLARE @year VARCHAR(4);
DECLARE @month VARCHAR(2);
-- START OF CONFIGURATION SECTION
-- THIS IS THE ONLY SECTION THAT SHOULD BE MODIFIED
-- SET THE YEAR AND MONTH PARAMETERS
SET @year = '2013';
SET @month = '3'; -- 1 = January.... 12 = Decemeber.
-- END OF CONFIGURATION SECTION
DECLARE @startDate DATE
DECLARE @endDate DATE
SET @startDate = @year + '-' + @month + '-01 00:00:00';
SET @endDate = DATEADD(MONTH, 1, @startDate);
SELECT
DATEPART(YEAR, dateTimeStamp) AS [Year]
, DATEPART(MONTH, dateTimeStamp) AS [Month]
, COUNT(*) AS NumStreams
, [platform] AS [Platform]
, deliverableName AS [Deliverable Name]
, SUM(billableDuration) AS NumSecondsDelivered
FROM
DeliveryTransactions
WHERE
dateTimeStamp >= @startDate
AND dateTimeStamp < @endDate
GROUP BY
DATEPART(YEAR, dateTimeStamp)
, DATEPART(MONTH, dateTimeStamp)
, [platform]
, deliverableName
ORDER BY
[platform]
, DATEPART(YEAR, dateTimeStamp)
, DATEPART(MONTH, dateTimeStamp)
, deliverableName
int
. – Aleks G Apr 11 '13 at 13:56YYYYMMDD
- only this format is guaranteed to work for any language and/or regional settings – marc_s Apr 11 '13 at 14:06YYYY-MM-DD
for aDATE
datatype - you're safe. ForDATETIME
however, it is NOT SAFE -- don't use it that way! UseYYYYMMDD
only (no dashes!). To demonstrate, run this little snippet of code in SQL Server Mgmt Studio:SET LANGUAGE german; SELECT CAST('2013-11-25' AS DATETIME)
- and you'll get a German error message telling you it cannot convert the string to aDATETIME
.SELECT CAST('20131125' AS DATETIME)
(without dashes!) works just fine. – marc_s Nov 28 '13 at 7:48