# 怎样才能在两个表获得要求得数据

recherlau 2002-01-10 09:17:46

struct mySEL {
AnsiString PRUNO;
int TOT_STK;//总进货
int STK_PIN;//进货件数
int STK_PBK;//退货件数
int STK_PCS;//库存件数
int STK_SAL;//销售件数
int STK_PNT;//进货订货件数
int STK_PONT;//销售订货件数
};
DynamicArray<mySEL>mySELArray;
//
void __declspec(dllexport) SqlSumSelNo(TQuery *Query,AnsiString database,bool T)
{
Query->DatabaseName=database;

Query->Close();
Query->SQL->Clear();
//
Query->FieldDefs->Clear();
//
if(T){
"sum(A.PCS) as SAl,"
"B.TOT_STK-sum(A.PCS) as PCS");
Query->SQL->Add("from DREPT as A,mSTOCK as B");
}
else
"sum(A.PCS)+sum(B.STK_PNT) as PNT");
Query->SQL->Add("from DPENT as A,mSTOCK as B");
}
Query->Open();
//
mySELArray.Length=Query->RecordCount;
if(!Query->Eof) {
for(int i=0;i<Query->RecordCount;i++){
Query->First();
if(T){
mySELArray[i].STK_SAL=Query->FieldByName("SAL")->AsInteger;
mySELArray[i].STK_PCS=Query->FieldByName("PCS")->AsInteger;
mySELArray[i].PRUNO=Query->FieldByName("PRUNO")->AsString;
}
else
{mySELArray[i].STK_PONT=Query->FieldByName("PNT")->AsInteger;
mySELArray[i].PRUNO=Query->FieldByName("PRUNO")->AsString;
}
Query->Next();
}
}
//
TTable *DB=DBM->mSTK;
for(int i=0;i<mySELArray.Length;i++){
/*Query->Close();
Query->SQL->Clear();
Query->Open();*/

DB->First();
while (!DB->Eof&&DB->FieldValues["PRUNO"]==mySELArray[i].PRUNO){
if(DB->State!=dsEdit) DB->Edit();
if(T){
DB->FieldValues["STK_SAL"]=mySELArray[i].STK_SAL;
DB->FieldValues["STK_PCS"]=mySELArray[i].STK_PCS;
}
else
{
DB->FieldValues["STK_PONT"]=mySELArray[i].STK_PONT;
}
DB->Next();
}

}
DB->Close();
...全文
9 点赞 收藏 回复

529

C++ Builder 茶馆

2002-01-10 09:17