I'm doing a query in SQL and with the following need in the table I have the document in two moments or status (1) when it originates and (2) when it is "linked to another process" the point is that when I generate the query only the records of moment 1 have a description and I also require it at time 2.
In my query I use a left join
to bring other values that depend on the documents related to the receipts, however I understand that by the logic of the query I can not understand the logic to be able to repeat the value according to the exposed up.
Select
T01."Transaction No_" AS "Transacción",
T01."Entry No_" AS "Registro",
T01."Entry Type" AS "TipoR",
T01."Cust_ Ledger Entry No_" AS "Rcte",
T01."Posting Date" AS "FechaR",
T01."Document No_" AS "Docto",
T01."Amount (LCY)" AS "Importe",
T01."Customer No_" AS "CFacturado",
T02."Name" AS "Nombre",
T03."Description" AS "Descripción",
T03."Bal_ Account No_" AS "Cta",
T03."Bal_ Account Type" AS "TipoCta",
T03."No_ Series" AS "Serie",
T04."Posting Date" AS "FechaR",
T04."Document No_" AS "Docto"
FROM
RTM1.dbo."BD$Detailed Cust_ Ledg_ Entry" "T01",
RTM1.dbo."BD$Customer" "T02",
RTM1.dbo."BD$Cust_ Ledger Entry" "T03"
Left Join
RTM1.dbo."BD$Cust_ Ledger Entry" "T04"
on
T03."Entry No_" = T04."Entry No_"
WHERE
"T01"."Customer No_" = "T02"."No_"
AND "T01"."Cust_ Ledger Entry No_" = "T03"."Entry No_"
AND T01."Posting Date" BETWEEN date1 and date2 "
The space of the red circle is where I want to repeat the information in common have the type of document (which does not appear here, the customer number and the document number: