当我为采购订单生成报表时,报表会复制产品代码的记录。
例如,采购订单是: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服务器中并通过查看代码导致其他产品代码的位置来运行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
答案 0 :(得分: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并不足以给你独特的结果。同一部件可能有多个分销商,或同一部件号可能有多个产品名称,例如不同的产品分销商使用相同的部件号和不同的产品。
答案 1 :(得分:0)
可能是这个GROUP BY子句
GROUP BY DistPartNo, DistProductName, Distributor, USSAProductCode
需要替换
GROUP BY DistPartNo, DistProductName, Distributor, UMTBProductCode