var sqlComplaint = "SELECT lc.complaintType, COUNT(*) AS complaintsReceived ";
sqlComplaint += "FROM complaints c LEFT OUTER JOIN ";
sqlComplaint += "lookup_complaint lc ON c.complaintType = lc.id ";
sqlComplaint += "WHERE (c.dateReceived BETWEEN CONVERT(DATETIME, '" + dateReceivedFrom + " 00:00:00', 102) AND CONVERT(DATETIME, '" + dateReceivedTo + " 23:59:59', 102)) ";
sqlComplaint += "GROUP BY lc.complaintType ";
sqlComplaint += "ORDER BY lc.complaintType";
AND
var sqlFinance = "SELECT lf.financeCompany, COUNT(*) AS complaintsReceived ";
sqlFinance += "FROM dbo.complaints c INNER JOIN ";
sqlFinance += "dbo.complaints_a ca ON c.aId = ca.id LEFT OUTER JOIN ";
sqlFinance += "dbo.lookup_finance_company_a lf ON ca.financeCompany = lf.id ";
sqlFinance += "WHERE (c.dateReceived BETWEEN CONVERT(DATETIME, '" + dateReceivedFrom + " 00:00:00', 102) AND CONVERT(DATETIME, '" + dateReceivedTo + " 23:59:59', 102)) ";
sqlFinance += "GROUP BY lf.financeCompany ";
sqlFinance += "ORDER BY lf.financeCompany";
These are my 2 statements, separately they return 2 tables like below:
Complaint Type , Count
"Complaint Name1", 2
"Complaint Name2", 6
etc...
I want to know how to write a statement to produce a table like the below:
finance type
Complaint Type "finance type1" "finance type2"
"complaint name1" 3 5
"complaint name2" 7 6
Complaint type crossed with finance type and a count of them showing.. if that makes sense??
sqlComplaint += "FROM complaints c LEFT OUTER JOIN ";
sqlComplaint += "lookup_complaint lc ON c.complaintType = lc.id ";
sqlComplaint += "WHERE (c.dateReceived BETWEEN CONVERT(DATETIME, '" + dateReceivedFrom + " 00:00:00', 102) AND CONVERT(DATETIME, '" + dateReceivedTo + " 23:59:59', 102)) ";
sqlComplaint += "GROUP BY lc.complaintType ";
sqlComplaint += "ORDER BY lc.complaintType";
AND
var sqlFinance = "SELECT lf.financeCompany, COUNT(*) AS complaintsReceived ";
sqlFinance += "FROM dbo.complaints c INNER JOIN ";
sqlFinance += "dbo.complaints_a ca ON c.aId = ca.id LEFT OUTER JOIN ";
sqlFinance += "dbo.lookup_finance_company_a lf ON ca.financeCompany = lf.id ";
sqlFinance += "WHERE (c.dateReceived BETWEEN CONVERT(DATETIME, '" + dateReceivedFrom + " 00:00:00', 102) AND CONVERT(DATETIME, '" + dateReceivedTo + " 23:59:59', 102)) ";
sqlFinance += "GROUP BY lf.financeCompany ";
sqlFinance += "ORDER BY lf.financeCompany";
These are my 2 statements, separately they return 2 tables like below:
Complaint Type , Count
"Complaint Name1", 2
"Complaint Name2", 6
etc...
I want to know how to write a statement to produce a table like the below:
finance type
Complaint Type "finance type1" "finance type2"
"complaint name1" 3 5
"complaint name2" 7 6
Complaint type crossed with finance type and a count of them showing.. if that makes sense??