/*
Alias: WORK
LiveAnswer: FALSE

*/

SELECT DentEconomics."Date", Doctors.LastName AS Doctor, DentEconomics.DentistID,
			DentEconomics.TransactionType, DentEconomics.SourceName, 
			DentEconomics.Credit, DentEconomics.CreditEURO, DentEconomics.EconomID,
			DentEconomics.PaymentText, DentEconomics.DueDate, DentEconomics.Description
FROM DentEconomics LEFT OUTER JOIN Doctors ON DentEconomics.DentistID = Doctors.DocID
WHERE DentEconomics.PaymentType = 2 AND DentEconomics.Sign = -1
UNION
SELECT PatEconomics."Date", Doctors.LastName AS Doctor, PatEconomics.DentistID,
			-1 AS TransactionType, PatEconomics.SourceName,
			PatEconomics.Credit, PatEconomics.CreditEURO, DentEconomics.EconomID,
			PatEconomics.PaymentText, PatEconomics.DueDate, PatEconomics.Description
FROM PatEconomics LEFT OUTER JOIN Doctors ON PatEconomics.DentistID = Doctors.DocID
WHERE PatEconomics.PaymentType = 2 AND PatEconomics.Sign = -1
