尝试计算如何从日期时间字段中减去分钟数。
select
'1' as PPCONO, b.new_SalesrepId as PPREP1,
MAX(a.ActualEnd - c.TimeZoneBias) as PPDATE,
count(b.new_SalesrepId) as PPCOUNT
from
ActivityPointerBase as a
join
SystemUserExtensionBase as b on b.SystemUserId = a.OwnerId
join
UserSettingsBase as c on c.SystemUserId = b.SystemUserId
where
b.new_SalesrepId <> '99999999'
and a.ActivityTypeCode = '4201'
and b.new_SalesrepId is not NULL
and a.StateCode = '1'
and CONVERT(varchar(8), a.ActualEnd, 112) = '20140627'
group by
b.new_SalesrepId, CONVERT(varchar(8), a.ActualEnd, 112)
order by
b.new_SalesrepId ASC;
从上面的代码中,部分MAX(a.ActualEnd - c.TimeZoneBias)
其中a.ActualEnd是被拉入的日期时间字段,而c.TimeZoneBias是我想要减去的分钟数。每次我运行它,它都会减少数天而不是分钟。在这种情况下,c.TimeZoneBias实际值为'300',因此它减去300天而不是300分钟。
答案 0 :(得分:4)
我发现最简单的方法是使用算术:
MAX(a.ActualEnd - c.TimeZoneBias / cast(24 * 60 as float)) as PPDATE
这会将TimeZoneBias
转换为一天的分数。
答案 1 :(得分:2)
使用DATEADD
减去特定时间间隔的特定数字,如下所示:
DATEADD(minute, (-1 * c.TimeZoneBias), a.ActualEnd )