Для этого потребуется ДИНАМИЧЕСКИЙ SQL.
Столбцы указаны в МЕСЯЦАХ, но переходить на дни - дело незначительное.
Пример
-- Generate Date Full Date Range
Declare @D1 date,@D2 date
Select @D1=Min(StartDate),@D2=Max(StartDate) from TBLTrips
Select Top (DateDiff(Month,@D1,@D2)+1) D=DateAdd(Month,-1+Row_Number() Over (Order By (Select Null)),@D1)
Into #Dates
From master..spt_values n1
-- Generate Columns
Declare @Cols varchar(max) = stuff( (Select ','+QuoteName(D) From #Dates Order by 1 For XML Path('')),1,1,'')
-- Generate Dynamic SQL
Declare @SQL varchar(max) = '
Select *
From (
Select Vehicle,StartDate,Odometer=sign(Odometer) From TBLTrips
Union
Select A.Vehicle
,B.D
,0
From TBLVehicles A
Cross Join #Dates B
) Src
Pivot (sum([Odometer]) For [StartDate] in (' + @Cols + ') ) p
Cross Apply ( Select Total = '+replace(@Cols,',','+')+' ) T
'
--Print @SQL
Exec(@SQL)
Возвращает
РЕДАКТИРОВАТЬ - Запрошенное ОБНОВЛЕНИЕ
Declare @D1 date,@D2 date
Select @D1=Min(convert(Date,TripStart)),@D2=Max(convert(Date,TripStart)) from EMS_trip_Data2
Select Top (DateDiff(DAY,@D1,@D2)+1) D=DateAdd(DAY,-1+Row_Number() Over (Order By (Select Null)),@D1)
Into #Dates
From master..spt_values n1
-- Generate Columns
Declare @Cols varchar(max) = stuff( (Select ','+QuoteName(D) From #Dates Order by 1 For XML Path('')),1,1,'')
-- Generate Dynamic SQL
Declare @SQL varchar(max) = '
Select *
From (
Select Vehicle,TripStart=convert(Date,TripStart),StartOdometer=sign(StartOdometer) From EMS_trip_Data2
Union
Select A.Vehicle
,B.D
,0
From VehicleSummary2 A
Cross Join #Dates B
) Src
Pivot (sum([StartOdometer]) For [TripStart] in (' + @Cols + ') ) p
Cross Apply ( Select Total = '+replace(@Cols,',','+')+' ) T
'
--Print @SQL
Exec(@SQL)
РЕДАКТИРОВАТЬ-2 с новой колонкой
Declare @D1 date,@D2 date
Select @D1=Min(convert(Date,TripStart)),@D2=Max(convert(Date,TripStart)) from EMS_trip_Data2
Select Top (DateDiff(DAY,@D1,@D2)+1) D=DateAdd(DAY,-1+Row_Number() Over (Order By (Select Null)),@D1)
Into #Dates
From master..spt_values n1
-- Generate Columns
Declare @Cols varchar(max) = stuff( (Select ','+QuoteName(D) From #Dates Order by 1 For XML Path('')),1,1,'')
-- Generate Dynamic SQL
Declare @SQL varchar(max) = '
Select *
From (
Select Src1.*,VS.[Group]
From (
Select Vehicle,TripStart=convert(Date,TripStart),StartOdometer=sign(StartOdometer) From EMS_trip_Data2
Union
Select A.Vehicle
,B.D
,0
From VehicleSummary2 A
Cross Join #Dates B
) src1
Join VehicleSummary2 VS on src1.Vehicle = VS.Vehicle
) Src
Pivot (sum([StartOdometer]) For [TripStart] in (' + @Cols + ') ) p
Cross Apply ( Select Total = '+replace(@Cols,',','+')+' ) T
'
--Print @SQL
Exec(@SQL)
Возвращает