您将使用
DATEDIFF:
declare @start datetimedeclare @end datetimeset @start = '2011-01-01'set @end = '2012-01-01'select DATEDIFF(d, @start, @end)results = 365
所以对于您的查询:
SELECT dtCreated , bActive , dtLastPaymentAttempt , dtLastUpdated , dtLastVisit , DATEDIFF(d, dtCreated, dtLastUpdated) as DifferenceFROM CustomersWHERe (bActive = 'true') AND (dtLastUpdated > ConVERT(DATETIME, '2012-01-0100:00:00', 102))



