插入多行数据报错?
//insert into so_sodetails(cSOCode,cInvCode,dPreDate,iQuantity,iTaxUnitPrice,&
//iMoney,iTax,iSum,iTaxRate,ID,dPreFinishDate,cDefine24,iSOsID)
//select :ls_ccode,cinvcode,denddate,orderqty,iTaxUnitprice,&
//imoney,itax,iSum,itaxrate,:ll_somain_id,dstartdate,cuscinvcode,0
//from pp_pomain
//where id = :ll_pp_id and rownumber > 0
//using sqlca;
//定义一个数组,用来存储dw_2每行的mainid值,用IN的方法来试试,如果不行,就用循环了。
//发现在循环中不好用IN
long ll_mainid[]
for ll_row = 1 to dw_2.rowcount()
ll_mainid[ll_row] = dw_2.getitemnumber(ll_row,"mainid")
insert into so_sodetails(cSOCode,cInvCode,dPreDate,iQuantity,iTaxUnitPrice,&
iMoney,iTax,iSum,iTaxRate,ID,dPreFinishDate,cDefine24,iSOsID)
select :ls_ccode,cinvcode,denddate,orderqty,iTaxUnitprice,&
imoney,itax,iSum,itaxrate,:ll_somain_id,dstartdate,cuscinvcode,0
from pp_pomain
where mainid = :ll_mainid[ll_row]
using sqlca;
next
如上两段代码。都是想插入多行数据,下面那个方法用的是循环,也不行,单行就可以,真是打破头想不明白,只好请教各位了。
[解决办法]
dw的参数用in当然可以的。在内嵌sql中不知道是否可行。没测试过。
应该不行,因为dw的参数可能在retrieve时已经展开成一个列表后才送入的。
如果自你的dw中取得一个列表,然后再插入数据,我想可以用动态SQL语句来串接,如
string ls_sql = "insert into table_xx select col_xxx from talbe_xxx where mainid in("
for i = 1 to rowcount
ls_sql += string(ll_id)
if i <> ll_rowcount then ls_sql += ","
next
ls_sql +=")"
...动态执行ls_sql语句。
//
也可以在循环中将mainid值写入一个表中,然后通过写入表的mainid来写一个插入语句。。呵呵。都可以达到目的。
------------------------
PB混淆器(5-12)防止反编译 http://chengg0769.download.csdn.net/
[解决办法]
long ll_mainid[]
for ll_row = 1 to dw_2.rowcount()
ll_mainid[ll_row] = dw_2.getitemnumber(ll_row,"mainid")
insert into so_sodetails(cSOCode,cInvCode,dPreDate,iQuantity,iTaxUnitPrice,&
iMoney,iTax,iSum,iTaxRate,ID,dPreFinishDate,cDefine24,iSOsID)
select :ls_ccode,cinvcode,denddate,orderqty,iTaxUnitprice,&
imoney,itax,iSum,itaxrate,:ll_somain_id,dstartdate,cuscinvcode,0
from pp_pomain
where mainid = :ll_mainid[ll_row]
using sqlca;
if sqlca.sqlocode = 0 then
commit;
else
MessageBox('',sqlca.sqlerrtext)//放前面就对了,如果放rollback后面是判断回滚的信息
rollback;
next