简体   繁体   中英

Records repeat for SSRS 2005 report

When I run a report for a purchase order, the report duplicates records for product codes.

For example the purchase order is: P000976, the report display the product code twice when it should only appear once. 45-5540 appears twice.

P000976 09-17-2012 15,040.00 15,040.00 0.00
45-5540 "Lordotic Cervical Spacer 10mm Lordotic Cervical Spacer 10mm" 20 20 0
45-5540 "Lordotic Cervical Spacer 10mm Lordotic Cervical Spacer 10mm" 20 20 0

When I put the report's SQL in SQL server and run the sql by seeing where the code cause the additional product code it is this line within the SQL:

join all_product_codes_VW p on q.distpartno = p.distpartno

select q.specialrequirement
, q.distpartno
, q.toproduce
, q.prodbegindate
, q.distributor
, rc.report_category_name
, s.productperpo
, r.ebi_released
, w.ebi_in_WIP
, p.distproductname
, tp.typeprefixdetail
, tp.cost
, '1' as ReportTotals

from all_required_vw q
left join all_shipped_grafts_new_VW s on (q.distpartno = s.distpartno and  q.specialrequirement = s.ponumber)
left join all_released_Grafts_VW r on q.distpartno = r.distpartno
left join all_in_WIP_VW w on q.distpartno = w.distpartno
join all_product_codes_VW p on q.distpartno = p.distpartno
join setup_tissue_prefix tp on q.typenumber = tp.typeprefix
join setup_report_category_1 rc on q.distributor = rc.report_category_id

where q.prodbegindate < @enddate
           and q.completed = '0'
            and rc.report_category_name  like  '%' + isnull(@tcustomer, '') + '%'
order by q.prodbegindate, p.distproductname

This is the SQL for the view for which the join creates the duplicate.

SELECT COUNT_BIG(*) AS BIG, DistPartNo, DistProductName, Distributor, UMTBProductCode
FROM  dbo.Setup_Distributor_Product_info
WHERE (Distributor <> '7') OR (Distributor IS NULL)
GROUP BY DistPartNo, DistProductName, Distributor, USSAProductCode 

If you comment out these lines

--, p.distproductname

--join all_product_codes_VW p on q.distpartno = p.distpartno

Does the query return single rows for each distpartno? If yes then you're right that the all_products_code_VW view is causing the multiple rows.

Run these two queries and look at how many rows are in each and it will give you a clue as to why this is:

Select * from all_required_vw where distpartno = '45-5540'
Select * from all_product_codes_VW where distpartno = '45-5540'

My guess is that joining on only the distpartno is not enough to give you unique results. There might be more than one distributor for the same part, or multiple productnames for the same part number, eg different distrubutors using the the same part number with different products.

Possible this GROUP BY clause

GROUP BY DistPartNo, DistProductName, Distributor, USSAProductCode 

need replace on this

GROUP BY DistPartNo, DistProductName, Distributor, UMTBProductCode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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