sql server - Conversion in SQL -
what code do?
sum(convert(decimal(12,2), convert(decimal(12,2), datediff(mi,thistimelastyear,timetoday))/60))
i understand query doing why have use convert decimal twice make statement work? got query produce result wanted want know why came me try before getting desired result.
because without both converts, first perform datediff_result/60
integer division, , then convert decimal.
there other ways force division not done between integers. simplest be:
sum(convert(decimal(12,2), datediff(mi,thistimelastyear,timetoday)/60.0))
but, since return type of sum()
defined decimal(38,s)
, if need control on data type, ought be:
convert(decimal(12,2),sum( datediff(mi,thistimelastyear,timetoday)/60.0))
Comments
Post a Comment