/*
Alias: WORK
LiveAnswer: FALSE

*/

SELECT DentEconomics."Date", DentEconomics.Credit, DentEconomics.CreditEURO, 
	DentEconomics.ReceiptCredit, DentEconomics.ReceiptCreditEURO, 
	DentEconomics.Sign, DentEconomics.ReceiptNo, DentEconomics.SourceName, DentEconomics.Description,
	DentEconomics.DentistID, DentEconomics.EconomID, Doctors.LastName AS Dentist
FROM DentEconomics LEFT OUTER JOIN Doctors ON DentEconomics.DentistID = Doctors.DocID
WHERE DentEconomics.TransactionType = 2 AND DentEconomics.DentistID > 0
UNION
SELECT DentEconomics."Date", DentEconomics.Credit, DentEconomics.CreditEURO,  
	DentEconomics.ReceiptCredit, DentEconomics.ReceiptCreditEURO, 
   DentEconomics.Sign, DentEconomics.ReceiptNo, DentEconomics.SourceName, DentEconomics.Description,
	DentEconomics.DentistID, DentEconomics.EconomID, CAST('' AS CHAR(30)) AS Dentist
FROM DentEconomics
WHERE DentEconomics.TransactionType = 2 AND (DentEconomics.DentistID = 0 OR DentEconomics.DentistID IS NULL)
ORDER BY DentEconomics."Date", DentEconomics.SourceName
