/*
Alias: WORK
LiveAnswer: FALSE

*/

SELECT Patient.PatientID, Patient.LastName + ' ' + Patient.FirstName AS FullName,
		"PatTotals2.sql".DentistID, 		
		"PatTotals2.sql".Total, "PatTotals2.sql".TotalEURO, "PatTotals2.sql"."LastPayDate"
FROM Patient LEFT OUTER JOIN 
		"PatTotals2.sql" ON Patient.TherapySessionID = "PatTotals2.sql".SessionID
WHERE ("PatTotals2.sql".Total IS NOT NULL) AND ("PatTotals2.sql".TotalEURO IS NOT NULL)
UNION
SELECT Patient.PatientID, Patient.LastName + ' ' + Patient.FirstName AS FullName,
		"PatTotals2.sql".DentistID, 		
		 0 AS Total, 0 AS TotalEURO, "PatTotals2.sql"."LastPayDate"
FROM Patient LEFT OUTER JOIN 
		"PatTotals2.sql" ON Patient.TherapySessionID = "PatTotals2.sql".SessionID
WHERE ("PatTotals2.sql".Total IS NULL) OR ("PatTotals2.sql".TotalEURO IS NULL)

