Right now I'm getting the sum of unused hours for a time period.. I am wanting to change it to where I get a sum of unused hours for that time period if it is in the future.. If today is the first day of the itineray or somewhere in the middle of it, then I want unused hours from tomorrow-the end of the itinerary period.
Any ideas?
select b.login as CreatedBy,
d.Fname,
d.lname as Lname,
a.providerid as ProviderID,
sum(e.available)as Unused,
convert(varchar,a.Scheduledate,101)as TravelStart,
convert(varchar,a.ScheduledateEnd,101) as TravelEnd,
a.County,
a.State,
convert(varchar,a.CreatedDate,101)as CreatedDate,
convert(varchar,a.LastEditedDate,101) as LastEditedDate,
a.LastEditedBy,
a.Description,
a.Zipcode,
g.county as SomeZipsIn,
g.state as State
from tproviderschedule a with(nolock)
left outer join users b with(nolock) on a.createdby = b.user_id
left outer join IC.resource_hiring c with(nolock) on a.providerid = c.masExamNum
left outer join IC.resource d with(nolock)on c.resourceid = d.id
left outer join IC.zips f with(nolock) on f.zip= left(a.zipcode,5)
left outer join IC.counties g with(nolock) on g.id=f.countyid
left outer join IS.Provider_Availability e with(nolock) on e.masexamnum = a.providerid
where convert(datetime, e.app_date,101) between convert(datetime, a.Scheduledate,101) and convert(datetime, a.ScheduledateEnd,101)
and convert(datetime,a.scheduledateend,101) >= convert(varchar, getdate(),101)
group by b.login, d.Fname,d.lname ,a.providerid ,a.Scheduledate,a.ScheduledateEnd,
a.County,a.State,a.CreatedDate,a.LastEditedDate,a.LastEditedBy,a.Description,a.Zipcode,g.county,g.state
order by a.providerid
Any ideas?
select b.login as CreatedBy,
d.Fname,
d.lname as Lname,
a.providerid as ProviderID,
sum(e.available)as Unused,
convert(varchar,a.Scheduledate,101)as TravelStart,
convert(varchar,a.ScheduledateEnd,101) as TravelEnd,
a.County,
a.State,
convert(varchar,a.CreatedDate,101)as CreatedDate,
convert(varchar,a.LastEditedDate,101) as LastEditedDate,
a.LastEditedBy,
a.Description,
a.Zipcode,
g.county as SomeZipsIn,
g.state as State
from tproviderschedule a with(nolock)
left outer join users b with(nolock) on a.createdby = b.user_id
left outer join IC.resource_hiring c with(nolock) on a.providerid = c.masExamNum
left outer join IC.resource d with(nolock)on c.resourceid = d.id
left outer join IC.zips f with(nolock) on f.zip= left(a.zipcode,5)
left outer join IC.counties g with(nolock) on g.id=f.countyid
left outer join IS.Provider_Availability e with(nolock) on e.masexamnum = a.providerid
where convert(datetime, e.app_date,101) between convert(datetime, a.Scheduledate,101) and convert(datetime, a.ScheduledateEnd,101)
and convert(datetime,a.scheduledateend,101) >= convert(varchar, getdate(),101)
group by b.login, d.Fname,d.lname ,a.providerid ,a.Scheduledate,a.ScheduledateEnd,
a.County,a.State,a.CreatedDate,a.LastEditedDate,a.LastEditedBy,a.Description,a.Zipcode,g.county,g.state
order by a.providerid