繁体   English   中英

将数据导出到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个重复记录。 有什么建议可以重建出口以避免重复记录吗?

您的联接将产生“重复项”,例如,您通过inventLocationIdinventDim联接可能会产生多个记录,因此您为每个这些记录“重复”一次inventTrans
重新评估您的查询以解决您的问题; 你可能想改变的一件事是链接到InventDim通过InventDimId

您的问题与CSV导出代码无关,因为您可以轻松查看是否将CSV文件操作替换为infolog的输出。

错误是您没有将Inventdim表与任何其他表连接。 因此,这将导致交叉连接。 因此,更改您的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM