第1个回答 2018-11-08
HSTMT stmt;
char * sqlquery="select branch_name,sum(balance) from account group by branch_name";
SQLAllocStmt(conn,&stmt);
error=SQLExecDirect(stmt,(SQLCHAR*)sqlquery,SQL_NTS);
if (error==SQL_SUCCESS)
{
SQLBindCol(stmt,1,SQL_C_CHAR,branchname,80,&lenOut1);
SQLBindCol(stmt,2,SQL_C_FLOAT,&balance,0,&lenOut2);
error=SQLFetch(stmt);
SQLGetDiagRec(SQL_HANDLE_STMT,stmt,RecNumber,SQLState, NativeErrorPtr,MessageText, BufferLength,TextLengthPtr);
cout<<SQLState<<":"<<MessageText<<endl;
while (SQLFetch(stmt)==SQL_SUCCESS){
printf("%s%g\n",branchname,balance);
}
}