Hello,
I am trying to join two tables and have the output include all eqmtids. The hist_eqmtlist table has all eqmtids but the hist_load table has only some. I need the output to include all eqmtids and nulls or zeros for the other columns. I thought an outer join would do it but alas, I have been stumped by a join again.
select hist_loads.shiftindex, eqmtid, sum (loadtons) as loadtons, sum (ex_tmcat01/3600)as oper, [name], excav
--into #t_loadex
from hist_eqmtlist
left outer join hist_loads on hist_loads.shiftindex = hist_eqmtlist.shiftindex
and hist_eqmtlist.eqmtid = hist_loads.excav
inner join enum_load_grp_type on hist_loads.[load] = enum_load_grp_type.num
WHERE hist_loads.shiftindex between @startd and @endd and Pdb.dbo.DefineEqmt(excav) = 'Ours'
and hist_loads.extraload = 0
Group by hist_loads.shiftindex, excav, [name], eqmtid
order by excav
So where am I going wrong? Is it because of the 'hist_eqmtlist.eqmtid = hist_loads.excav' bit? isn't that what an outer join is for?
Thanks for all the help
I am trying to join two tables and have the output include all eqmtids. The hist_eqmtlist table has all eqmtids but the hist_load table has only some. I need the output to include all eqmtids and nulls or zeros for the other columns. I thought an outer join would do it but alas, I have been stumped by a join again.
select hist_loads.shiftindex, eqmtid, sum (loadtons) as loadtons, sum (ex_tmcat01/3600)as oper, [name], excav
--into #t_loadex
from hist_eqmtlist
left outer join hist_loads on hist_loads.shiftindex = hist_eqmtlist.shiftindex
and hist_eqmtlist.eqmtid = hist_loads.excav
inner join enum_load_grp_type on hist_loads.[load] = enum_load_grp_type.num
WHERE hist_loads.shiftindex between @startd and @endd and Pdb.dbo.DefineEqmt(excav) = 'Ours'
and hist_loads.extraload = 0
Group by hist_loads.shiftindex, excav, [name], eqmtid
order by excav
So where am I going wrong? Is it because of the 'hist_eqmtlist.eqmtid = hist_loads.excav' bit? isn't that what an outer join is for?
Thanks for all the help