0

当我为采购订单运行报表时,报表会重复产品代码的记录。

例如采购订单是:P000976,报表显示产品代码两次,而它应该只出现一次。45-5540 出现两次。

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

当我将报告的 SQL 放入 SQL Server 并通过查看代码导致附加产品代码的位置来运行 sql 时,它是 SQL 中的这一行:

在 q.distpartno = p.distpartno 上加入 all_product_codes_VW p

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

这是连接为其创建副本的视图的 SQL。

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 
4

2 回答 2

0

可能的这个 GROUP BY 子句

GROUP BY DistPartNo, DistProductName, Distributor, USSAProductCode 

需要更换这个

GROUP BY DistPartNo, DistProductName, Distributor, UMTBProductCode
于 2013-02-26T09:32:33.557 回答
0

如果您注释掉这些行

--, p.distproductname

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

查询是否为每个 distpartno 返回单行?如果是,那么你是对的,all_products_code_VW 视图导致了多行。

运行这两个查询并查看每个查询中有多少行,它将为您提供有关原因的线索:

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

我的猜测是,仅加入 distpartno 不足以为您提供独特的结果。同一零件可能有多个分销商,或者同一零件编号可能有多个产品名称,例如,不同的分销商对不同的产品使用相同的零件编号。

于 2013-02-26T00:22:02.773 回答