diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index fa926cbd..5406eea1 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -215,6 +215,12 @@ DeletedAuditID int WITH EXECUTE AS OWNER AS BEGIN +--added rhm/jcb 20121218i +declare @tmpTable table +( + icontentid int primary key +) +insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1) --added jcb 20111122 declare @dts datetime set @dts = (select dts from items where itemid = @ProcItemID ) @@ -242,6 +248,7 @@ set @dts = (select dts from items where itemid = @ProcItemID ) where Number is not null --added jcb 20111028_1827 and ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) --end added jcb 20111028_1827 --added jcb 20111122 --and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID )) @@ -303,11 +310,12 @@ and ca.dts > @dts -- inner join tblitems ti on ca.contentid = ti.contentid WHERE ca.DeleteStatus = 0 AND --added jcb 20111028_1827 -ca.contentid != (select contentid from items where itemid = @procitemid) and +ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) --end added jcb 20111028_1827 --added jcb 20111122 --ca.dts > (select dts from items where itemid = @ProcItemID ) -(ca.dts > @dts or ca.actiondts > @dts) +and (ca.dts > @dts or ca.actiondts > @dts) --end added jcb 20111122 UNION SELECT distinct @@ -330,13 +338,14 @@ ca.contentid != (select contentid from items where itemid = @procitemid) and ,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID FROM ContentAudits ca -- inner join tblitems ti on ca.contentid = ti.contentid -WHERE ca.DeleteStatus > 0 AND +WHERE ca.DeleteStatus > 0 --added jcb 20111028_1827 --ca.contentid != (select contentid from items where itemid = @procitemid) and --end added jcb 20111028_1827 --added jcb 20111122 --ca.dts > (select dts from items where itemid = @ProcItemID ) -(ca.dts > @dts or ca.actiondts > @dts) +and ca.contentid in (select icontentid from @tmpTable) +and (ca.dts > @dts or ca.actiondts > @dts) --end added jcb 20111122 order by ca.DTS,ActionDTS @@ -362,6 +371,7 @@ order by ca.DTS,ActionDTS inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid where ca.auditid not in (select auditid from @report) and rpt.lastauditid is not null +and ca.contentid in (select icontentid from @tmpTable) return end GO diff --git a/PROMS/DataLoader/PROMStoAPPR.sql b/PROMS/DataLoader/PROMStoAPPR.sql index 966811fa..8b374004 100644 --- a/PROMS/DataLoader/PROMStoAPPR.sql +++ b/PROMS/DataLoader/PROMStoAPPR.sql @@ -2699,6 +2699,12 @@ DeletedAuditID int WITH EXECUTE AS OWNER AS BEGIN +--added rhm/jcb 20121218i +declare @tmpTable table +( + icontentid int primary key +) +insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1) --added jcb 20111122 declare @dts datetime set @dts = (select dts from items where itemid = @ProcItemID ) @@ -2726,6 +2732,7 @@ set @dts = (select dts from items where itemid = @ProcItemID ) where Number is not null --added jcb 20111028_1827 and ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) --end added jcb 20111028_1827 --added jcb 20111122 --and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID )) @@ -2787,11 +2794,42 @@ and ca.dts > @dts -- inner join tblitems ti on ca.contentid = ti.contentid WHERE ca.DeleteStatus = 0 AND --added jcb 20111028_1827 -ca.contentid != (select contentid from items where itemid = @procitemid) and +ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) --end added jcb 20111028_1827 --added jcb 20111122 --ca.dts > (select dts from items where itemid = @ProcItemID ) -(ca.dts > @dts or ca.actiondts > @dts) +and (ca.dts > @dts or ca.actiondts > @dts) +--end added jcb 20111122 + UNION + SELECT distinct +5 src, +-- cast(ident_current('contentaudits') + 1 as bigint) auditid +-- (select max(auditid) + 1 from contentaudits) [AuditID] + ca.[AuditID] + ,ca.[ContentID] + ,[Number] + ,[Text] + ,[Type] + ,[FormatID] + ,[Config] + ,ca.[DTS] cadts + ,ca.[UserID] + ,ca.[DeleteStatus] + ,ActionDTS + ,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS +,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID +,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID + FROM ContentAudits ca +-- inner join tblitems ti on ca.contentid = ti.contentid +WHERE ca.DeleteStatus > 0 +--added jcb 20111028_1827 + --ca.contentid != (select contentid from items where itemid = @procitemid) and +--end added jcb 20111028_1827 +--added jcb 20111122 +--ca.dts > (select dts from items where itemid = @ProcItemID ) +and ca.contentid in (select icontentid from @tmpTable) +and (ca.dts > @dts or ca.actiondts > @dts) --end added jcb 20111122 order by ca.DTS,ActionDTS @@ -2817,6 +2855,7 @@ order by ca.DTS,ActionDTS inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid where ca.auditid not in (select auditid from @report) and rpt.lastauditid is not null +and ca.contentid in (select icontentid from @tmpTable) return end GO diff --git a/PROMS/DataLoader/PROMStoCM.sql b/PROMS/DataLoader/PROMStoCM.sql index 35e11b90..62b810ef 100644 --- a/PROMS/DataLoader/PROMStoCM.sql +++ b/PROMS/DataLoader/PROMStoCM.sql @@ -2508,8 +2508,20 @@ DeletedAuditID int WITH EXECUTE AS OWNER AS BEGIN +--added rhm/jcb 20121218i +declare @tmpTable table +( + icontentid int primary key +) +insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1) +--added jcb 20111122 +declare @dts datetime +set @dts = (select dts from items where itemid = @ProcItemID ) +--set @dts = (SELECT .[dbo].[vefn_GetPreviousRevisionDTSByItemID] (@ProcItemID)) +--end added jcb 20111122 insert into @Report - SELECT + SELECT +1 src, [AuditID] ,ca.[ContentID] ,[Number] @@ -2517,7 +2529,7 @@ BEGIN ,[Type] ,[FormatID] ,[Config] - ,ca.[DTS] + ,ca.[DTS] cadts ,ca.[UserID] ,ca.[DeleteStatus] ,ActionDTS @@ -2527,8 +2539,50 @@ BEGIN FROM ContentAudits ca -- inner join tblitems ti on ca.contentid = ti.contentid where Number is not null +--added jcb 20111028_1827 +and ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) +--end added jcb 20111028_1827 +--added jcb 20111122 +--and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID )) +and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > @dts) +--and ca.dts > (select dts from items where itemid = @ProcItemID ) +and ca.dts > @dts +--end added jcb 20111122 +-- UNION +-- SELECT +--2 src, +-- cast(ident_current('contentaudits') + 1 as bigint) auditid +---- (select max(auditid) + 1 from contentaudits) [AuditID] +---- 0 [AuditID] +-- ,ca.[ContentID] +-- ,[Number] +-- ,[Text] +-- ,[Type] +-- ,[FormatID] +-- ,[Config] +-- ,ca.[DTS] cadts +-- ,ca.[UserID] +-- ,ca.[DeleteStatus] +-- ,ActionDTS +-- ,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS +--,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID +--,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID +-- FROM tblContents ca +---- inner join tblitems ti on ca.contentid = ti.contentid +--WHERE ca.DeleteStatus = 0 AND +----added jcb 20111028_1827 +--ca.contentid != (select contentid from items where itemid = @procitemid) and +----end added jcb 20111028_1827 +----ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID )) +----added jcb 20111122 +----ca.ContentID in (SELECT [ContentID] FROM Contents where dts > (select dts from items where itemid = @ProcItemID )) +--ca.ContentID in (SELECT [ContentID] FROM Contents where dts > @dts) +----end added jcb 20111122 +----order by ca.DTS,ActionDTS UNION - SELECT + SELECT +3 src, cast(ident_current('contentaudits') + 1 as bigint) auditid -- (select max(auditid) + 1 from contentaudits) [AuditID] -- 0 [AuditID] @@ -2538,7 +2592,7 @@ BEGIN ,[Type] ,[FormatID] ,[Config] - ,ca.[DTS] + ,ca.[DTS] cadts ,ca.[UserID] ,ca.[DeleteStatus] ,ActionDTS @@ -2547,10 +2601,70 @@ BEGIN ,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID FROM tblContents ca -- inner join tblitems ti on ca.contentid = ti.contentid - WHERE ca.DeleteStatus = 0 AND - (ca.ContentID in (SELECT [ContentID] FROM ContentAudits) or - ca.dts > (select dts from items where itemid = @ProcItemID )) - order by ca.DTS,ActionDTS +WHERE ca.DeleteStatus = 0 AND +--added jcb 20111028_1827 +ca.contentid != (select contentid from items where itemid = @procitemid) +and ca.contentid in (select icontentid from @tmpTable) +--end added jcb 20111028_1827 +--added jcb 20111122 +--ca.dts > (select dts from items where itemid = @ProcItemID ) +and (ca.dts > @dts or ca.actiondts > @dts) +--end added jcb 20111122 + UNION + SELECT distinct +5 src, +-- cast(ident_current('contentaudits') + 1 as bigint) auditid +-- (select max(auditid) + 1 from contentaudits) [AuditID] + ca.[AuditID] + ,ca.[ContentID] + ,[Number] + ,[Text] + ,[Type] + ,[FormatID] + ,[Config] + ,ca.[DTS] cadts + ,ca.[UserID] + ,ca.[DeleteStatus] + ,ActionDTS + ,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS +,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID +,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID + FROM ContentAudits ca +-- inner join tblitems ti on ca.contentid = ti.contentid +WHERE ca.DeleteStatus > 0 +--added jcb 20111028_1827 + --ca.contentid != (select contentid from items where itemid = @procitemid) and +--end added jcb 20111028_1827 +--added jcb 20111122 +--ca.dts > (select dts from items where itemid = @ProcItemID ) +and ca.contentid in (select icontentid from @tmpTable) +and (ca.dts > @dts or ca.actiondts > @dts) +--end added jcb 20111122 +order by ca.DTS,ActionDTS + + insert into @Report + SELECT +4 src, + ca.[AuditID] + ,ca.[ContentID] + ,ca.[Number] + ,ca.[Text] + ,ca.[Type] + ,ca.[FormatID] + ,ca.[Config] + ,ca.[DTS] cadts + ,ca.[UserID] + ,ca.[DeleteStatus] + ,ca.ActionDTS + ,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS +,(select max(auditid) from contentaudits where ca.contentid = contentid and ca.auditid > auditid and number is not null) LastAuditID +,(select max(auditid) from contentaudits where ca.contentid = contentid and ca.auditid > auditid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID + FROM ContentAudits ca +-- inner join tblitems ti on ca.contentid = ti.contentid + inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid +where ca.auditid not in (select auditid from @report) +and rpt.lastauditid is not null +and ca.contentid in (select icontentid from @tmpTable) return end GO