我们突然在"未结供应商交易"中有很多红手。由于缺乏数据库维护计划,我们遇到了奇怪的问题,现在系统已经启动并运行,但出现了太多的红手。
我在 MS:http://support.microsoft.com/kb/894412 上看到了这个
但这不是很实际,因为它不是一个冒犯性的记录,而是很多。
有没有办法在事务SQL中快速发现不应该出现的标记事务?
在SpecTrans VS VendTransOpen中寻找孤儿是一个好的开始吗?
谢谢!
编辑:考虑到这一点,在SpecTrans中查找孤立记录可能无济于事,因为红手可能意味着交易是在SpecTrans中找到的...
编辑#2:我发现这可以取消标记某些交易,但是当我按照建议进行操作时,我找不到任何相关的日记帐。这可能是问题所在。
备份表后,这就是我最终所做的:
delete from SPECTRANS where SPECTRANS.RECID in
(
select st.RECID from VENDTRANS vt
inner join VENDTRANSOPEN vto on vto.REFRECID = vt.RECID
inner join SPECTRANS st on st.REFRECID = vto.RECID
where st.SPECTABLEID=470 and st.DATAAREAID in ('company1', 'company2')
)
红手"的原因有时可能是指向不再存在的LedgerJournalTrans
记录的SpecTrans
记录。
用于删除它们的作业(仅限当前公司):
static void RedHandDirtyVendRemove(Args _args)
{
SpecTrans st;
VendTrans vt;
VendTransOpen vto;
LedgerJournalTrans ljt;
while select count(RecId) from st
group SpecTableId
where st.RefTableId == tableNum(VendTransOpen) &&
st.SpecCompany == curext() &&
st.RefCompany == curext()
exists join vto
where vto.RecId == st.RefRecId
{
info(strFmt('%1: %2', st.RecId, tableId2name(st.SpecTableId)));
}
while select st
where st.RefTableId == tableNum(VendTransOpen) &&
st.SpecTableId == tableNum(LedgerJournalTrans) &&
st.SpecCompany == curext() &&
st.RefCompany == curext()
join vto
where vto.RecId == st.RefRecId
join vt
where vt.RecId == vto.RefRecId
notExists join ljt
where ljt.RecId == st.SpecRecId
{
info(strFmt('%1: %2 %3', st.RecId, vt.Voucher, vt.AccountNum));
}
delete_from st
where st.RefTableId == tableNum(VendTransOpen) &&
st.SpecTableId == tableNum(LedgerJournalTrans) &&
st.SpecCompany == curext() &&
st.RefCompany == curext()
exists join vto
where vto.RecId == st.RefRecId
exists join vt
where vt.RecId == vto.RefRecId
notExists join ljt
where ljt.RecId == st.SpecRecId;
info(strFmt('%1', st.RowCount()));
}