buen dia
tengo el siguiente comando para un crystal report de entrega (remision) pero no puedo agregar sentencia para que me traiga los lotes de entrega en SAP se que es OBTN Y BTN3 pero no me deja relacionarlos
agradezco si me pueden ayudar
gracias
SELECT DISTINCT V5."AbsEntry",
IFNULL((SELECT SUM(I5."WTAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='FUENTE'),0) as "FUENTE",
IFNULL((SELECT SUM(I5."WTAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='ICA'),0) AS "ICA",
IFNULL((SELECT SUM(I5."WTAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='IVA'),0) AS "IVA",
IFNULL((SELECT MAX(W."PrctBsAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='FUENTE'),0) AS "%FUENTE",
IFNULL((SELECT MAX(W."PrctBsAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='ICA'),0) AS "%ICA",
IFNULL((SELECT MAX(W."PrctBsAmnt") FROM "{?Schema@}".DLN5 I5
INNER JOIN "{?Schema@}".OWHT W ON W."WTCode"=I5."WTCode"
WHERE I5."AbsEntry"=V5."AbsEntry" AND W."U_Tipo"='IVA'),0) AS "%IVA",
T0."DocEntry", T0."DocNum", T0."Printed", T0."DocDate",
LEFT(T0."DocTime", LENGTH(T0."DocTime")-2)||':'||RIGHT(T0."DocTime",2) AS "DocTime", T0."CreateDate",
T0."DocDueDate", T2."CardName", T0."VatSum", T0."DocTotal",
T0."Comments", T0."TotalExpns", T0."Address2",
T1."ItemCode", T1."Dscription", T1."Quantity", T1."VatPrcnt", T1."Price", T2."Phone1", T0."DocCur",
T1."LineTotal",T0."SysRate" AS "DocRate",
T2."Fax", T2."LicTradNum", T3."DocNum", T4."SlpName", T0."DiscSum",
T5."PymntGroup", T0."U_MedioPg", T6."Rate", T1."Currency", T7."SalUnitMsr",T3."NumAtCard",
CAST(T0."U_SEI_Obs" AS NVARCHAR) AS "U_SEI_Obs",
CASE WHEN T0."CurSource" = 'L' THEN '$'
WHEN T0."CurSource" ='C' THEN T0."DocCur" ELSE 'USD' END AS "Moneda",
T0."DocTotalFC",T8."BeginStr"
FROM "{?Schema@}".ODLN T0
INNER JOIN "{?Schema@}".DLN1 T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN "{?Schema@}".OCRD T2 ON T0."CardCode" = T2."CardCode"
LEFT JOIN "{?Schema@}".ODLN T3 ON T1."BaseEntry" = T3."DocEntry"
INNER JOIN "{?Schema@}".OSLP T4 ON T0."SlpCode" = T4."SlpCode"
INNER JOIN "{?Schema@}".OCTG T5 ON T0."GroupNum" = T5."GroupNum"
LEFT JOIN "{?Schema@}".DLN5 V5 ON V5."AbsEntry"=T0."DocEntry"
LEFT JOIN "{?Schema@}".ORTT T6 ON T6."RateDate"= T0."DocDate" AND T6."Currency"= T0."CurSource"
LEFT JOIN "{?Schema@}".OITM T7 ON T7."ItemCode"= T1."ItemCode"
LEFT JOIN "{?Schema@}".NNM1 T8 ON T8."Series"= T0."Series"
WHERE T0."DocEntry" = {?Dockey@}
AND (CASE WHEN (SELECT IFNULL(J0."U_SOL_imprime_lista",'S') FROM "{?Schema@}".ODLN J0 WHERE J0."DocEntry"=T0."DocEntry")='N'
AND T1."TreeType" = 'I' THEN 'NN' ELSE 'SS' END) = 'SS'