SELECT DISTINCT dbo.QMS.QMSCode, dbo.QMS.QMSSerial, dbo.QMS.model, dbo.QMS.controlType, dbo.QMS.connectionType, dbo.QMS.generateType, dbo.QMS.isCamera, dbo.QMS.centralMonitorRowCount, dbo.QMS.TV_LCD, dbo.QMS.callNumber, dbo.QMS.monitorNumber, dbo.QMS.centralMonitorNumber, dbo.QMS.description, dbo.QMS.lastUsedBranchCode, dbo.QMS.lastUsedCompanyCode, dbo.QMS.warrantyStartDate, dbo.QMS.warrantyEndDate, dbo.QMS.warrantyType, dbo.QMS.lastCheckDate, dbo.QMS.isActive, dbo.Branch.name AS BranchName, dbo.Company.name AS CompanyName, (CASE WHEN (EXISTS (SELECT [Order].done FROM [Order] WHERE done = 'FALSE')) THEN CAST(1 AS Bit) ELSE CAST(0 AS Bit) END) AS OrderDone, (CASE WHEN (EXISTS (SELECT [DefectReport].done FROM DefectReport, QMS WHERE DefectReport.done = 'TRUE' AND [DefectReport].productCode = QMS.QMSCode)) THEN CAST(1 AS Bit) ELSE CAST(0 AS Bit) END) AS DefectDone FROM dbo.QMS LEFT OUTER JOIN dbo.Company ON dbo.QMS.lastUsedCompanyCode = dbo.Company.companyCode LEFT OUTER JOIN dbo.Branch ON dbo.QMS.lastUsedBranchCode = dbo.Branch.branchCode LEFT OUTER JOIN dbo.[Order] ON dbo.QMS.QMSCode = dbo.[Order].productCode CROSS JOIN dbo.DefectReport