en su momento realice con un cliente un proyecto de tiempos en procesos a lo cual por este tema tuve que separa las consultas , este va enfocado a ventas entre proceso y proceso lo que marcaba la diferencia era el join de tablas
este es de facturas res
SELECT distinct T0.[DocNum] 'Pedido',t0.CANCELED,
T0.[CardCode]'SN',
T0.[CardName]'NOMBRE',
t5.DocNum 'Factura',
t3.DocNum 'Entega',
t6.DocEntry 'Devolución',
t8.DocNum'NC'
-------------PED_FACT------------------
,cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra] AS FECHA_PED
,cast(convert(varchar(10),T5.CREATEDATE,112) as Varchar(15)) +' ' + T5.[u_resumencompra] AS FECHA_FAC
,DATEdiff (HOUR, cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra],cast(convert(varchar(10),T5.CREATEDATE,112) AS Varchar(15)) +' ' + T5.[u_resumencompra]) HORAS_PED_FAC
-----------------FACT-ENTREGA-------------
,cast(convert(varchar(10),T5.CREATEDATE,112) as Varchar(15)) +' ' + T5.[u_resumencompra] AS FECHA_FAC
,cast(convert(varchar(10),T3.CREATEDATE,112) as Varchar(15)) +' ' + T3.[u_resumencompra] AS FECHA_ENT
,isnull(DATEdiff (HOUR, cast(convert(varchar(10),T5.CREATEDATE,112) as Varchar(15)) +' ' + T5.[u_resumencompra],cast(convert(varchar(10),T3.CREATEDATE,112) AS Varchar(15)) +' ' + T3.[u_resumencompra]),0) HORAS_FAC_ENT
------------------------SUMA-------------
,isnull(DATEdiff (HOUR, cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra],cast(convert(varchar(10),T5.CREATEDATE,112) AS Varchar(15)) +' ' + T5.[u_resumencompra]),0)
+ isnull(DATEdiff (HOUR, cast(convert(varchar(10),T5.CREATEDATE,112) as Varchar(15)) +' ' + T5.[u_resumencompra],cast(convert(varchar(10),T3.CREATEDATE,112) AS Varchar(15)) +' ' + T3.[u_resumencompra]),0) TOTAL_HORAS
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
left join INV1 T4 on t4.BaseEntry=t0.DocEntry
left join OINV T5 on t5.DocEntry=t4.DocEntry
LEFT join dln1 T2 on T2.baseentry = t5.docentry
LEFT join odln T3 on T3.docentry = T2.docentry and t2.linenum = T2.baseline
left join RDN1 T6 on t3.docentry = t6.baseEntry
left join RIN1 t7 on t7.BaseEntry = t5.DocEntry
left join ORIN T8 ON t8.DocEntry = t7.DocEntry
WHERE datepart(year,T0.[TAXDate]) in (2017,2018) and T0.[docnum] IN ( '13936', '17390', '17391') and t0.[CANCELEd] ='N' and T5.[isIns]='y'
order by t0.DocNum asc
este es de factura deudor
SELECT distinct T0.[DocNum] 'Pedido',t0.CANCELED,
T0.[CardCode]'SN',
T0.[CardName]'NOMBRE',
t5.DocNum 'Factura',
t3.DocNum 'Entega',
t6.DocEntry 'Devolución',
t8.DocNum'NC'
-------------PED_FACT------------------
,cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra] AS FECHA_PED
,cast(convert(varchar(10),T3.CREATEDATE,112) as Varchar(15)) +' ' + T3.[u_resumencompra] AS FECHA_ENT
,DATEdiff (HOUR, cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra],cast(convert(varchar(10),T3.CREATEDATE,112) AS Varchar(15)) +' ' + T3.[u_resumencompra]) HORAS_PED_ENT
-----------------ENTREGA-FACTU-------------
,cast(convert(varchar(10),T3.CREATEDATE,112) as Varchar(15)) +' ' + T3.[u_resumencompra] AS FECHA_ENT
,cast(convert(varchar(10),T5.CREATEDATE,112) as Varchar(15)) +' ' + T5.[u_resumencompra] AS FECHA_FAC
,isnull(DATEdiff (HOUR, cast(convert(varchar(10),T3.CREATEDATE,112) as Varchar(15)) +' ' + T3.[u_resumencompra],cast(convert(varchar(10),T5.CREATEDATE,112) AS Varchar(15)) +' ' + T5.[u_resumencompra]),0) HORAS_ENT_FAC
------------------------SUMA-------------
,isnull(DATEdiff (HOUR, cast(convert(varchar(10),T0.CREATEDATE,112) as Varchar(15)) +' ' + T0.[u_resumencompra],cast(convert(varchar(10),T3.CREATEDATE,112) AS Varchar(15)) +' ' + T3.[u_resumencompra]),0)
+ isnull(DATEdiff (HOUR, cast(convert(varchar(10),T3.CREATEDATE,112) as Varchar(15)) +' ' + T3.[u_resumencompra],cast(convert(varchar(10),T3.CREATEDATE,112) AS Varchar(15)) +' ' + T5.[u_resumencompra]),0) TOTAL_HORAS
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT join dln1 T2 on T2.baseentry = t0.docentry and t1.linenum = T2.baseline
LEFT join odln T3 on T3.docentry = T2.docentry
left join INV1 T4 on t4.BaseEntry=t3.DocEntry
left join OINV T5 on t5.DocEntry=t4.DocEntry
left join RDN1 T6 on t3.docentry = t6.baseEntry
left join RIN1 t7 on t7.BaseEntry = t5.DocEntry
left join ORIN T8 ON t8.DocEntry = t7.DocEntry
WHERE datepart(year,T0.[TAXDate]) in (2017,2018) and T0.[docnum] IN ( '17392', '17379') and t0.[CANCELEd] ='N'
order by t0.DocNum asc