/*
Alias: WORK
LiveAnswer: FALSE

*/

SELECT EXTRACT(MONTH FROM DentEconomics."Date") AS DateMonth, 
		EXTRACT(YEAR FROM DentEconomics."Date") AS DateYear, DentEconomics."Date",
		-DentEconomics.Credit AS Credit, -DentEconomics.CreditEURO AS CreditEURO, DentEconomics.DentistID,
		EXTRACT(MONTH FROM DentEconomics."Date") + EXTRACT(YEAR FROM DentEconomics."Date") * 12 AS DateMonthYear,
		Sign, -TransactionType-1 AS Type, EconomID
FROM DentEconomics
WHERE Sign = -1
UNION
SELECT EXTRACT(MONTH FROM DentEconomics."Date") AS DateMonth, 
		EXTRACT(YEAR FROM DentEconomics."Date") AS DateYear, DentEconomics."Date",
		DentEconomics.Credit, DentEconomics.CreditEURO, DentEconomics.DentistID,
		EXTRACT(MONTH FROM DentEconomics."Date") + EXTRACT(YEAR FROM DentEconomics."Date") * 12 AS DateMonthYear,
		Sign, 2 AS Type, EconomID
FROM DentEconomics
WHERE TransactionType = 2  AND Sign = 1 
UNION
SELECT EXTRACT(MONTH FROM PatEconomics."Date") AS DateMonth, 
		EXTRACT(YEAR FROM PatEconomics."Date") AS DateYear, PatEconomics."Date",
		PatEconomics.Credit, PatEconomics.CreditEURO, PatEconomics.DentistID,
		EXTRACT(MONTH FROM PatEconomics."Date") + EXTRACT(YEAR FROM PatEconomics."Date") * 12 AS DateMonthYear,
		-Sign AS Sign, 1 AS Type, EconomID
FROM PatEconomics
WHERE Sign = -1
