Como están espero me puedan ayudar, estoy trabajando en este query tratando de seleccionar el ultimo documento creado de venta, pero quiero que también pueda seleccionar el almacén espero me puedan ayudar, actualmente me trae el ultimo documento pero cuando filtro con el almacén no me muestra nada
SELECT
'Factura Deudor' AS "Tipo Documento",
T0."NumAtCard",
T0."U_EASY_PED_BOR" AS "No EasySales",
T0."DocTime" AS "Hora Creación Documento",
T0."DocNum" AS "No. de Documento",
CASE WHEN T0."DocStatus" = 'O' THEN 'Abierto' ELSE 'Cerrado' END AS "Estado",
T0."DocDate",
T0."DocDueDate",
T0."CardCode",
T0."CardName",
T02."ListName" AS "LP. SN Actual",
T1."CogsOcrCod" AS "Canal",
T3."SlpName" AS "Cod. Asesor",
T3."Memo" AS "Nom. Asesor",
T1."ItemCode",
T1."Dscription",
T1."WhsCode",
T2."WhsName",
T1."Quantity",
T4."U_SEI_LITROS",
T4."U_SEI_GALONES",
T5."Name" AS "Retenido",
T6."Name" AS "Causal de retención",
T0."U_TAC_Easynet_AP"
FROM OINV T0
INNER JOIN OCRD T01 ON T0."CardCode" = T01."CardCode"
INNER JOIN OPLN T02 ON T01."ListNum" = T02."ListNum"
INNER JOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN OWHS T2 ON T1."WhsCode" = T2."WhsCode"
INNER JOIN OSLP T3 ON T0."SlpCode" = T3."SlpCode"
LEFT JOIN OITM T4 ON T1."ItemCode" = T4."ItemCode"
LEFT JOIN "TEAMAVANZASAS"."@TAC_RETENIDO" T5 ON T0."U_TAC_Retenido" = T5."Code"
LEFT JOIN "TEAMAVANZASAS"."@TAC_CAUSALRETENCION" T6 ON T0."U_TAC_CausalRetencion" = T6."Code"
WHERE T0."DocEntry" = (SELECT MAX(T20."DocEntry") FROM OINV T20) AND T1."WhsCode" = [%0]