将表达式转换为数据类型datetime-in存储过程的算术溢出错误

时间:2014-10-09 19:32:20

标签: sql-server datepart

我尽可能多地为这个问题找到答案,但无法提出解决方案。

我们最近将我们的应用程序从SQL 2008移至2012年。这在2008年没有遇到任何问题。

我只会在我认为错误存在的地方添加SP的部分,在2014-02-01为@startdate和2014-02-运行此存储过程时会出现上述错误消息28为@enddate。

ALTER PROCEDURE [dbo].[Action_UpdateRProfitabilityReportTable9-21-09]
@startdate datetime,
@enddate datetime,
@vehiclemaintence float,
@fleetops float,
@driverrate float,
@helperrate float,
@fuelrate float

AS



INSERT INTO [dbo].[rprofitabilityreport]

(Route, Material, Helper, monthofyear, monthyear, sitecount, totalstops , RecurringRevenue, WORevenue, DumpTons, DumpFees,
FuelPumped, Miles, TotalHours, FuelCosts, VehicleMaintence, FleetOPs, LaborCosts,
BenefitFactor, ActualDumpRate, RouteExpenses, RouteExpensesperStop, CardboardDump, MixPaperDump) 




left join (select distinct sh.route, sh.routemonth, sh.monthyr, count(sh.siteid) AS SiteCount
from (select sh.siteid, sh.route, datepart(mm,sh.servicedate) AS RouteMonth, left(cast(datepart(yyyy, sh.servicedate) as varchar(4)),4) + '-' + right('00' + cast(datepart(mm, sh.servicedate) as varchar(2)),2) AS MonthYR, count(sh.servicehistoryuid) As RouteCount
from [dbo].[ServiceHistory_vw_With_ServiceUID] sh
where sh.servicedate between @startdate and @enddate
group by sh.siteid, sh.route, datepart(mm,sh.servicedate), datepart(yyyy, sh.servicedate)) as sh
group by sh.route, sh.routemonth, sh.monthyr) rc ON rc.route = a1.route and rc.monthyr = a1.monthyr) RS

0 个答案:

没有答案