sql - Outer apply on another outer apply? -


i have problem sql request working on.

i return total number of item ordered customer. problem is: more 1 line when execute request.

(please note very simplified version of request comprehension of code. tables not named this, neither rows.)

select outerpallet.pallet palletnbr, id, shipmentid arandomtable outer apply (select sum(palletnbr) pallet thepallettable group arandomtable.id) outerpallet id = @something 

what get:

palletnbr  id    shipmentid 1          2     340 2          3     340 3          4     340  

what (whitout having id , shipmentid):

palletnbr 6 

to have lines in one. thought of doing outer apply, won't work (since doing outer apply of outer apply)...

i thought of maybe doing outer apply in way, can't seem find out how. tried add:

group shipmentid 

but have in outer apply, , can't seem figure out how put there.

would have idea me solve problem ? little hint of great !

i realize query might more complicated. version in question seems more answers join cross apply:

select sum(palletnbr) palletnbr, arandomtable.id, arandomtable.shipmentid arandomtable left outer join      thepallettable       on thepallettable.randomid = arandomtable.id arandomtable.id = @something group arandomtable.id, arandomtable.shipmentid; 

is there reason need cross apply?


Comments