
CREATE VIEW [dbo].[blOrderDuplicatesView]
as
select d.ID ErpId, NumerPelny NumberString, order_id.Data OrderId, d.Data  from  dbo.DokHandlowe d
JOIN dbo.Features order_id ON order_id.Name='bl_order_id' and order_id.Parent = d.ID and order_id.Lp =0 and order_id.ParentType='DokHandlowe'
and order_id.Data in (
select f.Data from dbo.Features f
JOIN dbo.DokHandlowe ddd ON f.Parent = ddd.ID and ddd.NumerSymbol NOT LIKE 'KWPZ%'
where  Name='bl_order_id' and Lp =0 and ParentType='DokHandlowe'

GROUP BY f.Data HAVING count(*)>1)
where NumerSymbol NOT LIKE 'KWPZ%'
--ORDER BY order_id.Data;
GO


