Click to See Complete Forum and Search --> : MFC SQL join


kronski
September 20th, 1999, 10:04 AM
I am trying to use the MFC ODBC database classes to solve a particular problem. However, knowing only the basics, I am unable to figure out how to implement a recordset for SQL statements that will contain a "join" command. For example, I need to implement the statement:

select count(nameid), max(currentdate)
from events join eventday on events.dayid = eventday.dayid
group by eventday.dayid
order by eventday.dayid

This joins the tables "events" and "eventday". What is the procedure for doing something like this using MFC?

Thanks in advance.

Thomas Ascher
September 20th, 1999, 10:15 AM
Hi. To execute SQL statements without deriving a new class from CRecordset, you can call CRecordset itself by supplying the SQL statement:

CRecordset set(pDatabase);
CString strSelect = "SELECT SUM(Field1) FROM TestTable", strValue;

set.Open(CRecordset::forwardOnly, strSelect, CRecordset::readOnly |
CRecordset::noDirtyFieldCheck | CRecordset::executeDirect);
set.GetFieldValue(0, strValue); // use GetFieldValue to get the field values, because
double dSum = atof(strValue); // we haven't derived a class with member variables
set.Close();