Print ''
Print '---------------------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Procedures    : [REPORTS_NativFilesAnalyse]'
Print ' Creation      : 29.08.2021/J.Fes'
Print ' Last.Update   : 27.12.2021/J.Fes'

use [#DB_N#]

Print ''
Print ' '
Print '---------------------------------------------------------------------------------------'
Print '--------------------- R E P O R T S - Nativ Files Analyse -----------------------------'
Print '---------------------------------------------------------------------------------------'
Print ''

--------------------------------------------------------------------------------
Print '-- [Rrt_410_List_NXNativ_Dublicates] ----------------------------------'
If Exists (select Name from sysobjects where type = "P" and
           Name = "Rrt_410_List_NXNativ_Dublicates")
Drop Procedure Rrt_410_List_NXNativ_Dublicates
GO
CREATE PROCEDURE Rrt_410_List_NXNativ_Dublicates
       (
        @ObjectFromSiteID nvarchar(32),
        @ProcStateCol nvarchar(14),
        @ObjectClass nvarchar(10),
        @ObjectType1 nvarchar(32),
        @ObjectType2 nvarchar(32)
       )


AS
begin
  DECLARE @DebugPrintOn bit
  set @DebugPrintOn = 0
  DECLARE @MyProcName nvarchar(32)
  set @MyProcName='Rrt_410_List_NXNativ_Dublicates'
  DECLARE @ExecuteSQLstr nvarchar(max)

--   DECLARE @AndProcessData_UDF nvarchar(32)
--   set @AndProcessData_UDF='DS_AndProcessData_UDF'
--   if @ObjectClass = 'DS' set @AndProcessData_UDF='DS_AndProcessData_UDF'
--   if @ObjectClass = 'IR' set @AndProcessData_UDF='IRs_AndProcessData_UDF'
--   if @ObjectClass = 'I'  set @AndProcessData_UDF='ITEMs_AndProcessData_UDF'

DECLARE @dupIrToItem TABLE (File_NE nvarchar(128), CountN INT)

-- INSERT INTO @dupIrToItem
-- SELECT
--  -- IR_DS.IR_DbId,
--  DS.ObjectFs_NE,
--  Count(1) as RelCount
-- FROM
--   dbo.Objects_tbl IR
--   INNER JOIN dbo.DS_IR_rel_View IR_DS ON (IR.Id = IR_DS.IR_DbId)
--   INNER JOIN dbo.Objects_tbl DS ON (IR_DS.DS_DbId = DS.Id)
-- WHERE
--   DS.ObjectType IN (@ObjectType1,@ObjectType2)
--   and DS.ObjectFromSiteID like @ObjectFromSiteID
-- GROUP BY
--   -- IR_DS.IR_DbId,
--    DS.ObjectFs_NE
-- HAVING
--   Count(1) > 1

INSERT INTO @dupIrToItem
SELECT
 -- IR_DS.IR_DbId,
 DS.ObjectName,
 Count(1) as RelCount
FROM
  dbo.Objects_tbl IR
  INNER JOIN dbo.DS_IR_rel_View IR_DS ON (IR.Id = IR_DS.IR_DbId)
  INNER JOIN dbo.Objects_tbl DS ON (IR_DS.DS_DbId = DS.Id)
WHERE
  DS.ObjectType IN (@ObjectType1,@ObjectType2)
  and DS.ObjectFromSiteID like @ObjectFromSiteID
GROUP BY
  -- IR_DS.IR_DbId,
   DS.ObjectName
HAVING
  Count(1) > 1


select * from @dupIrToItem
end
GO

----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
Print '-- [Report_911_NXNativ_Dublicates] ---------------------------------'
If Exists (select Name from sysobjects where type = "P" and
           Name = "Report_911_NXNativ_Dublicates")
Drop Procedure Report_911_NXNativ_Dublicates
GO
CREATE PROCEDURE Report_911_NXNativ_Dublicates
       (
        @ObjectFromSiteID nvarchar(32) ,
        @ProcStateCol nvarchar(14),
        @ObjectClass nvarchar(10)
       )
AS
begin
 Execute Rrt_410_List_NXNativ_Dublicates @ObjectFromSiteID, @ProcStateCol, @ObjectClass, 'UGMASTER','UGMASTER'
end
GO




Print ''
Print '---------------------------------------------------------------------------------------'
Print ' R E P O R T S imported to #DB_N#'
Print '---------------------------------------------------------------------------------------'
GO
