将数据导出到 CSV 时出现双记录
Double records when exporting data to CSV
我创建了一个将数据导出到 CSV 文件的方法,我创建了以下代码:
public void export()
{
permission = new FileIOPermission(fileNameValue, #io_WRITE);
permission.assert();
inFile = new CommaTextIo(fileNameValue, #io_WRITE);
inFile.inFieldDelimiter(";");
inFile.inRecordDelimiter("\n");
while (inFile.status() == IO_Status::Ok)
while select inventTrans
where inventTrans.StatusIssue == StatusIssue::ReservPhysical
join inventDim
where inventDim.InventLocationId == inventLocationId
join inventTransOrg
where inventTransOrg.RecId == inventTrans.InventTransOrg
{
con = conNull();
con = conIns(con, 1, inventTransOrg.inventTransId);
con = conIns(con, 2, inventLocationId);
con = conIns(con, 3, inventTrans.Qty);
inFile.writeExp(con);
}
}
这将创建一个包含 3 列的 CSV 文件,但有很多双记录(将近 100 个)实际数据不包含 100 个双记录。有什么建议可以重建导出以避免双重记录吗?
您的联接将产生 'duplicates',例如您通过 inventLocationId
加入 inventDim
可能会产生多个记录,因此您的 inventTrans
是 'repeated' 每条记录一次。
重新评估您的查询以解决您的问题;您可能想要更改的一件事是通过 InventDimId
链接到 InventDim
。
您的问题与 CSV 导出代码无关,因为如果您将 CSV 文件操作替换为 infolog
的输出,您可以很容易地看到。
错误在于您没有将 Inventdim table 与任何其他 table 一起加入。所以它会导致交叉连接。因此,更改您的 while 语句以包含它。我的建议是添加字段列表,因为 InventTrans 将有很多字段,为了获得更好的性能,建议为 select 语句添加字段列表。
您也可以尝试使用以下语句。
While select inventTransId from inventTransOrg
join Qty from inventTrans
where inventTrans.InventTransOrg = inventTransOrg.RecId
join inventLocationId from inventDim
where inventDim.InventDimId == inventTrans.InventDimId
&& inventDim.InventLocationId == inventLocationId
我创建了一个将数据导出到 CSV 文件的方法,我创建了以下代码:
public void export()
{
permission = new FileIOPermission(fileNameValue, #io_WRITE);
permission.assert();
inFile = new CommaTextIo(fileNameValue, #io_WRITE);
inFile.inFieldDelimiter(";");
inFile.inRecordDelimiter("\n");
while (inFile.status() == IO_Status::Ok)
while select inventTrans
where inventTrans.StatusIssue == StatusIssue::ReservPhysical
join inventDim
where inventDim.InventLocationId == inventLocationId
join inventTransOrg
where inventTransOrg.RecId == inventTrans.InventTransOrg
{
con = conNull();
con = conIns(con, 1, inventTransOrg.inventTransId);
con = conIns(con, 2, inventLocationId);
con = conIns(con, 3, inventTrans.Qty);
inFile.writeExp(con);
}
}
这将创建一个包含 3 列的 CSV 文件,但有很多双记录(将近 100 个)实际数据不包含 100 个双记录。有什么建议可以重建导出以避免双重记录吗?
您的联接将产生 'duplicates',例如您通过 inventLocationId
加入 inventDim
可能会产生多个记录,因此您的 inventTrans
是 'repeated' 每条记录一次。
重新评估您的查询以解决您的问题;您可能想要更改的一件事是通过 InventDimId
链接到 InventDim
。
您的问题与 CSV 导出代码无关,因为如果您将 CSV 文件操作替换为 infolog
的输出,您可以很容易地看到。
错误在于您没有将 Inventdim table 与任何其他 table 一起加入。所以它会导致交叉连接。因此,更改您的 while 语句以包含它。我的建议是添加字段列表,因为 InventTrans 将有很多字段,为了获得更好的性能,建议为 select 语句添加字段列表。 您也可以尝试使用以下语句。
While select inventTransId from inventTransOrg
join Qty from inventTrans
where inventTrans.InventTransOrg = inventTransOrg.RecId
join inventLocationId from inventDim
where inventDim.InventDimId == inventTrans.InventDimId
&& inventDim.InventLocationId == inventLocationId