#define EXTERN
#include "btpcomm.h"
#include "btpcmmcr.h"
#include "sqlenv.h"
main()
{
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION ;
char txnbrh[12+1];
char txndt[10+1];
long txncnt;
EXEC SQL END DECLARE SECTION;
EXEC SQL update gcdgbnk set devlogrrn=0 where 1=1;
if ((sqlca.sqlcode != 0 ) && (sqlca.sqlcode != 100))
{
sprintf( cGlbWk, "update gcdgbnk err %d", sqlca.sqlcode );
BtpApDisp( cPrgID, cGlbWk );
BtpBatReturn(BATPROCDRUNERR, "数据库操作失败");
return(-1);
}
EXEC SQL INSERT INTO nmgtact SELECT brhid, :txndt, count(*), sum(txnamt)
FROM gctact
WHERE txndate = :txndt
AND mchtype = '6050'
AND revcd = '0'
GROUP BY brhid;
if ((sqlca.sqlcode != 0 ) && (sqlca.sqlcode != 100))
{
sprintf( cGlbWk, "insert into nmgtact err %d", sqlca.sqlcode );
BtpApDisp( cPrgID, cGlbWk );
BtpBatReturn(BATPROCDRUNERR, "数据库操作失败");
return(-1);
}
BtpBatReturn(BATPROCDRUNOK, "");
return;
}
静态嵌入SQL语句的应用程序:
1)include语句定义并描叙了SQLCA的结构。SQLCA用于应用程序和数据库之间的通讯,其中SQLCODE返回SQL语句执行后的结果状态。
2)在BEGIN DECLARE SECTION和END DECLARE SECTION之间定义了宿主变量。宿主变量可被SQL语句引用,也可以被C语言语句引用。它用于将程序中的数据通过SQL语句传给数据库管理器,或从数据库管理器接收查询的结果。在SQL语句中,主变量前均有“:”标志以示区别
3)在gctact中选择brhid,插入nmgtact表;