Search code examples
mysqlsqljasper-reports

Unable to Filter out the repeating values in iReport


I have a report that is supposed to show the part and quantity based on the location selected. It is a modified version of the Costing Layer Valuation in Fishbowl.

I have been able to get the location filtering to work but now the values are being duplicated and I am unable to figure out why.

These are screenshots to show the print out of the report when the Print All Repeating check box is unchecked and checked. Checked- With Repeating Unchecked- Without Repeating

This is my SQL Query


SELECT 
costlayer.qty AS Qty, costlayer.orgqty, costlayer.orgtotalcost,
costlayer.totalcost AS TotalCost, costlayer.datecreated AS DateCreated,
part.num AS PartNumber, part.description as PartDescription, asaccount.name as "InventoryAccount",
company.name AS company, currency.symbol

FROM CostLayer
LEFT JOIN Part ON part.id = costlayer.partid
LEFT JOIN Tag ON part.id = tag.partId
LEFT JOIN Location ON tag.locationId = location.id
LEFT JOIN LocationGroup ON location.locationGroupId = locationGroup.id
LEFT JOIN asaccount ON part.inventoryaccountid = asaccount.id
JOIN company ON company.id = 1
LEFT JOIN currency ON currency.homeCurrency = 1

WHERE 
costlayer.datecreated BETWEEN $P{dateRange1} AND $P{dateRange2}
AND costlayer.statusid IN ($P!{ckShowActiveCostingLayers},$P!{ckShowFulfilledCostingLayers},$P!{ckShowVoidedCostingLayers})
AND UPPER(part.num) LIKE UPPER($P{partNum})
AND (UPPER(COALESCE(asaccount.name,'')) LIKE UPPER('%' || $P{AssetAccount} || '%'))
AND LocationGroup.id LIKE $P{locationGroupID}

ORDER BY (CASE WHEN $P{AssetAccount} NOT LIKE CAST('%' AS varchar(256)) THEN asaccount.name ELSE part.num END), part.num ASC, costlayer.id, costlayer.datecreated

Solution

  • In looking at your screen shots it appears it's duplicating based on the number of tags in each location. This would be from the join on tags to be able to filter the locations. By adding a distinct to your query it will weed out the duplicate database values. After doing that you'll probably want to turn back on the show duplicate values as it will then not show if you make the same quantity and value of purchases for a given part.

    SELECT DISTINCT costlayer.qty AS Qty, costlayer.orgqty, costlayer.orgtotalcost,
    costlayer.totalcost AS TotalCost, costlayer.datecreated AS DateCreated,
    part.num AS PartNumber, part.description as PartDescription, asaccount.name as "InventoryAccount",
    company.name AS company, currency.symbol
    
    FROM CostLayer
    LEFT JOIN Part ON part.id = costlayer.partid
    LEFT JOIN Tag ON part.id = tag.partId
    LEFT JOIN Location ON tag.locationId = location.id
    LEFT JOIN LocationGroup ON location.locationGroupId = locationGroup.id
    LEFT JOIN asaccount ON part.inventoryaccountid = asaccount.id
    JOIN company ON company.id = 1
    LEFT JOIN currency ON currency.homeCurrency = 1
    
    WHERE costlayer.datecreated BETWEEN $P{dateRange1} AND $P{dateRange2}
    AND costlayer.statusid IN ($P!{ckShowActiveCostingLayers},$P!{ckShowFulfilledCostingLayers},$P!{ckShowVoidedCostingLayers})
    AND UPPER(part.num) LIKE UPPER($P{partNum})
    AND (UPPER(COALESCE(asaccount.name,'')) LIKE UPPER('%' || $P{AssetAccount} || '%'))
    AND LocationGroup.id LIKE $P{locationGroupID}
    
    ORDER BY (CASE WHEN $P{AssetAccount} NOT LIKE CAST('%' AS varchar(256)) THEN asaccount.name ELSE part.num END), part.num ASC, costlayer.id, costlayer.datecreated