Added vefn_GetMyChronology user function

Fixed getContentAuditsChronologyByItemID stored procedure
Fixed getContentAuditsSummaryByItemID stored procedure
Fixed getAnnotationAuditsChronologyByItemID stored procedure
This commit is contained in:
Rich 2012-11-13 16:08:14 +00:00
parent 43b06c1abd
commit 77338c048d
3 changed files with 834 additions and 336 deletions

View File

@ -592,6 +592,79 @@ IF (@@Error = 0) PRINT 'Procedure Creation: PasteItemSiblingBefore Succeeded'
ELSE PRINT 'Procedure Creation: PasteItemSiblingBefore Error on Creation' ELSE PRINT 'Procedure Creation: PasteItemSiblingBefore Error on Creation'
GO GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_GetMyChronology]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_GetMyChronology];
GO
/****** Object: UserDefinedFunction [dbo].[vefn_GetMyChronology] Script Date: 11/07/2012 18:09:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_GetMyChronology](@ProcItemID int, @ItemID int, @IncludeDeletedChildren int)
RETURNS @Chrono TABLE
(
[AuditID] bigint,
[ContentID] int,
[Number] nvarchar(max),
[Text] nvarchar(max),
[Type] int,
[FormatID] int,
[Config] nvarchar(max),
[DTS] datetime,
[UserID] nvarchar(max),
[DeleteStatus] int,
[ActionDTS] datetime,
[ActionWhat] nvarchar(max),
[ActionWhen] datetime,
[Path] nvarchar(max),
ItemID int,
TypeName nvarchar(max),
ordinalpath nvarchar(max)
)
WITH EXECUTE AS OWNER
AS
BEGIN
insert into @Chrono
select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
from
(
select
case
when lastauditid is null then 'Added'
when r.deletestatus > 0 then 'Deleted'
when lastauditid = -1 then 'Changed'
when DeletedAuditID is not null then 'Restored'
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
else 'Changed'
end actionwhat
,actiondts actionwhen
-- ,case
-- when lastauditid is null then dts
-- when r.deletestatus > 0 then ActionDTS
-- when lastauditid = -1 then dts
-- when DeletedAuditID is not null then ActionDTS
-- else dts
-- end actionwhen
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
,*
from vefn_tblchilditems (@ProcItemID,@ItemID,@IncludeDeletedChildren) t
inner join vefn_chronologyreport(@ProcItemID) r
on t.icontentid = r.contentid
-- where ActionDTS > procdts or dts > procdts
) ah
order by OrdinalPath, contentid,auditid--actionwhen
RETURN
END
go
IF (@@Error = 0) PRINT 'TableFunction [vefn_GetMyChronology] Succeeded'
ELSE PRINT 'TableFunction [vefn_GetMyChronology] Error on Creation'
go
/****** Object: StoredProcedure [dbo].[getContentAuditsChronologyByItemID] Script Date: 03/21/2012 15:58:26 ******/ /****** Object: StoredProcedure [dbo].[getContentAuditsChronologyByItemID] Script Date: 03/21/2012 15:58:26 ******/
SET ANSI_NULLS ON SET ANSI_NULLS ON
GO GO
@ -622,34 +695,35 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin begin
select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
from -- select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
( -- from
select -- (
case -- select
when lastauditid is null then 'Added' -- case
when r.deletestatus > 0 then 'Deleted' -- when lastauditid is null then 'Added'
when lastauditid = -1 then 'Changed' -- when r.deletestatus > 0 then 'Deleted'
when DeletedAuditID is not null then 'Restored' -- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' -- when DeletedAuditID is not null then 'Restored'
else 'Changed' ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
end actionwhat -- else 'Changed'
,actiondts actionwhen -- end actionwhat
-- ,case --,actiondts actionwhen
-- when lastauditid is null then dts ---- ,case
-- when r.deletestatus > 0 then ActionDTS ---- when lastauditid is null then dts
-- when lastauditid = -1 then dts ---- when r.deletestatus > 0 then ActionDTS
-- when DeletedAuditID is not null then ActionDTS ---- when lastauditid = -1 then dts
-- else dts ---- when DeletedAuditID is not null then ActionDTS
-- end actionwhen ---- else dts
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName ---- end actionwhen
,* --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t -- ,*
inner join vefn_chronologyreport(@ProcedureItemID) r -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
on t.icontentid = r.contentid -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- where ActionDTS > procdts or dts > procdts -- on t.icontentid = r.contentid
) ah ---- where ActionDTS > procdts or dts > procdts
order by OrdinalPath, contentid,auditid--actionwhen -- ) ah
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
go go
@ -658,6 +732,195 @@ IF (@@Error = 0) PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Suc
ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation' ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation'
go go
/****** Object: StoredProcedure [getContentAuditsSummaryByItemID] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsSummaryByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getContentAuditsSummaryByItemID];
GO
/****** Object: StoredProcedure [getContentAuditsSummaryByItemID] ******/
/*
getContentAuditsSummaryByItemID 146,146,0
getContentAuditsSummaryByItemID 42,42,0
getContentAuditsSummaryByItemID 9,9,0
getContentAuditsSummaryByItemID 146,146,1
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE PROCEDURE [dbo].[getContentAuditsSummaryByItemID]
(
@ProcedureItemID int,
@SelectedItemID int,
@IncludeDeletedChildren int
)
WITH EXECUTE AS OWNER
AS
begin
DECLARE @Chrono TABLE
(
[AuditID] bigint,
[ContentID] int,
[Number] nvarchar(max),
[Text] nvarchar(max),
[Type] int,
[FormatID] int,
[Config] nvarchar(max),
[DTS] datetime,
[UserID] nvarchar(max),
[DeleteStatus] int,
[ActionDTS] datetime,
[ActionWhat] nvarchar(max),
[ActionWhen] datetime,
[Path] nvarchar(max),
ItemID int,
TypeName nvarchar(max),
ordinalpath nvarchar(max)
)
insert into @Chrono
select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
select * from @Chrono
where AuditID is null OR AuditID in (select min(auditID) from @Chrono group by contentid UNION select max(auditID) from @Chrono group by contentid)
order by OrdinalPath, contentid,auditid
--select z.* from
--(
--select contentid,min(auditid) auditid from
--(
-- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) x
--group by contentid
--) y
--inner join
--(
-- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) z on y.contentid = z.contentid and y.auditid = z.auditid
--union
--select z.* from
--(
--select contentid,max(auditid) auditid from
--(
-- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) x
--group by contentid
--) y
--inner join
--(
-- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) z on y.contentid = z.contentid and y.auditid = z.auditid
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN
end
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: getContentAuditsSummaryByItemID Succeeded'
ELSE PRINT 'Procedure Creation: getContentAuditsSummaryByItemID Error on Creation'
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixSearchString]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixSearchString]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_FixSearchString]; DROP FUNCTION [vefn_FixSearchString];
GO GO
@ -1053,6 +1316,17 @@ AS
begin begin
declare @dts datetime declare @dts datetime
set @dts = (select dts from items where itemid = @procitemid) set @dts = (select dts from items where itemid = @procitemid)
declare @tci table
(
ItemID int,
IContentID int,
IDeleteStatus int,
ProcDTS datetime,
Path nvarchar(max),
OrdinalPath nvarchar(max)
)
insert into @tci
select * from vefn_tblchilditems(@ProcItemID,@ItemID,0)
select select
case case
when lastauditid is null and dts > itemdts then 'Added' when lastauditid is null and dts > itemdts then 'Added'
@ -1090,7 +1364,7 @@ begin
,tci.ordinalpath ,tci.ordinalpath
from tblannotations aa from tblannotations aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid join @tci tci on tci.itemid = ii.itemid
where aa.deletestatus = 0 where aa.deletestatus = 0
union union
select select
@ -1112,9 +1386,9 @@ join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid
,tci.ordinalpath ,tci.ordinalpath
from annotationaudits aa from annotationaudits aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid join @tci tci on tci.itemid = ii.itemid
) ah ) ah
where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0)) where itemid in (select itemid from @tci)
and dts > @dts and dts > @dts
--(select dts from versions where versionid = (select max(versionid) from revisions rr inner join versions vv on rr.revisionid = vv.revisionid --(select dts from versions where versionid = (select max(versionid) from revisions rr inner join versions vv on rr.revisionid = vv.revisionid
--inner join stages ss on vv.stageid = ss.stageid where itemid = @procitemid and ss.isapproved = 1)) --inner join stages ss on vv.stageid = ss.stageid where itemid = @procitemid and ss.isapproved = 1))

View File

@ -703,6 +703,17 @@ AS
begin begin
declare @dts datetime declare @dts datetime
set @dts = (select dts from items where itemid = @procitemid) set @dts = (select dts from items where itemid = @procitemid)
declare @tci table
(
ItemID int,
IContentID int,
IDeleteStatus int,
ProcDTS datetime,
Path nvarchar(max),
OrdinalPath nvarchar(max)
)
insert into @tci
select * from vefn_tblchilditems(@ProcItemID,@ItemID,0)
select select
case case
when lastauditid is null and dts > itemdts then 'Added' when lastauditid is null and dts > itemdts then 'Added'
@ -737,8 +748,10 @@ begin
,(select min(dts) from tblitems where itemid = ii.itemid) ItemDTS ,(select min(dts) from tblitems where itemid = ii.itemid) ItemDTS
,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid) LastAuditID ,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid) LastAuditID
,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and deletestatus > 0 and aa.dts = dts) DeletedAuditID ,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and deletestatus > 0 and aa.dts = dts) DeletedAuditID
,tci.ordinalpath
from tblannotations aa from tblannotations aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join @tci tci on tci.itemid = ii.itemid
where aa.deletestatus = 0 where aa.deletestatus = 0
union union
select select
@ -757,14 +770,16 @@ begin
,(select min(dts) from tblitems where itemid = ii.itemid) ItemDTS ,(select min(dts) from tblitems where itemid = ii.itemid) ItemDTS
,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and aa.auditid > auditid ) LastAuditID ,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and aa.auditid > auditid ) LastAuditID
,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and aa.auditid > auditid and deletestatus > 0 and aa.dts = dts) DeletedAuditID ,(select max(auditid) from annotationaudits where annotationid = aa.annotationid and itemid = ii.itemid and aa.auditid > auditid and deletestatus > 0 and aa.dts = dts) DeletedAuditID
,tci.ordinalpath
from annotationaudits aa from annotationaudits aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join @tci tci on tci.itemid = ii.itemid
) ah ) ah
where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0)) where itemid in (select itemid from @tci)
and dts > @dts and dts > @dts
--(select dts from versions where versionid = (select max(versionid) from revisions rr inner join versions vv on rr.revisionid = vv.revisionid --(select dts from versions where versionid = (select max(versionid) from revisions rr inner join versions vv on rr.revisionid = vv.revisionid
--inner join stages ss on vv.stageid = ss.stageid where itemid = @procitemid and ss.isapproved = 1)) --inner join stages ss on vv.stageid = ss.stageid where itemid = @procitemid and ss.isapproved = 1))
order by annotationid,auditid--actionwhen order by ordinalpath,annotationid,auditid--actionwhen
end end
GO GO
-- Display the status of Proc creation -- Display the status of Proc creation
@ -1008,6 +1023,79 @@ IF (@@Error = 0) PRINT 'Procedure Creation: getContentAuditsByContentIDandDTS Su
ELSE PRINT 'Procedure Creation: getContentAuditsByContentIDandDTS Error on Creation' ELSE PRINT 'Procedure Creation: getContentAuditsByContentIDandDTS Error on Creation'
GO GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_GetMyChronology]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_GetMyChronology];
GO
/****** Object: UserDefinedFunction [dbo].[vefn_GetMyChronology] Script Date: 11/07/2012 18:09:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_GetMyChronology](@ProcItemID int, @ItemID int, @IncludeDeletedChildren int)
RETURNS @Chrono TABLE
(
[AuditID] bigint,
[ContentID] int,
[Number] nvarchar(max),
[Text] nvarchar(max),
[Type] int,
[FormatID] int,
[Config] nvarchar(max),
[DTS] datetime,
[UserID] nvarchar(max),
[DeleteStatus] int,
[ActionDTS] datetime,
[ActionWhat] nvarchar(max),
[ActionWhen] datetime,
[Path] nvarchar(max),
ItemID int,
TypeName nvarchar(max),
ordinalpath nvarchar(max)
)
WITH EXECUTE AS OWNER
AS
BEGIN
insert into @Chrono
select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
from
(
select
case
when lastauditid is null then 'Added'
when r.deletestatus > 0 then 'Deleted'
when lastauditid = -1 then 'Changed'
when DeletedAuditID is not null then 'Restored'
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
else 'Changed'
end actionwhat
,actiondts actionwhen
-- ,case
-- when lastauditid is null then dts
-- when r.deletestatus > 0 then ActionDTS
-- when lastauditid = -1 then dts
-- when DeletedAuditID is not null then ActionDTS
-- else dts
-- end actionwhen
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
,*
from vefn_tblchilditems (@ProcItemID,@ItemID,@IncludeDeletedChildren) t
inner join vefn_chronologyreport(@ProcItemID) r
on t.icontentid = r.contentid
-- where ActionDTS > procdts or dts > procdts
) ah
order by OrdinalPath, contentid,auditid--actionwhen
RETURN
END
go
IF (@@Error = 0) PRINT 'TableFunction [vefn_GetMyChronology] Succeeded'
ELSE PRINT 'TableFunction [vefn_GetMyChronology] Error on Creation'
go
/****** Object: StoredProcedure [getContentAuditsChronologyByItemID] ******/ /****** Object: StoredProcedure [getContentAuditsChronologyByItemID] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsChronologyByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsChronologyByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getContentAuditsChronologyByItemID]; DROP PROCEDURE [getContentAuditsChronologyByItemID];
@ -1034,34 +1122,35 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin begin
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
from -- select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
( -- from
select -- (
case -- select
when lastauditid is null then 'Added' -- case
when r.deletestatus > 0 then 'Deleted' -- when lastauditid is null then 'Added'
when lastauditid = -1 then 'Changed' -- when r.deletestatus > 0 then 'Deleted'
when DeletedAuditID is not null then 'Restored' -- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' -- when DeletedAuditID is not null then 'Restored'
else 'Changed' ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
end actionwhat -- else 'Changed'
,actiondts actionwhen -- end actionwhat
-- ,case --,actiondts actionwhen
-- when lastauditid is null then dts ---- ,case
-- when r.deletestatus > 0 then ActionDTS ---- when lastauditid is null then dts
-- when lastauditid = -1 then dts ---- when r.deletestatus > 0 then ActionDTS
-- when DeletedAuditID is not null then ActionDTS ---- when lastauditid = -1 then dts
-- else dts ---- when DeletedAuditID is not null then ActionDTS
-- end actionwhen ---- else dts
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName ---- end actionwhen
,* --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t -- ,*
inner join vefn_chronologyreport(@ProcedureItemID) r -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
on t.icontentid = r.contentid -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- where ActionDTS > procdts or dts > procdts -- on t.icontentid = r.contentid
) ah ---- where ActionDTS > procdts or dts > procdts
order by OrdinalPath, contentid,auditid--actionwhen -- ) ah
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
GO GO
@ -1096,137 +1185,161 @@ CREATE PROCEDURE [dbo].[getContentAuditsSummaryByItemID]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin begin
DECLARE @Chrono TABLE
select z.* from
( (
select contentid,min(auditid) auditid from [AuditID] bigint,
( [ContentID] int,
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName [Number] nvarchar(max),
from [Text] nvarchar(max),
( [Type] int,
select [FormatID] int,
case [Config] nvarchar(max),
when lastauditid is null then 'Added' [DTS] datetime,
when r.deletestatus > 0 then 'Deleted' [UserID] nvarchar(max),
when lastauditid = -1 then 'Changed' [DeleteStatus] int,
when DeletedAuditID is not null then 'Restored' [ActionDTS] datetime,
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' [ActionWhat] nvarchar(max),
else 'Changed' [ActionWhen] datetime,
end actionwhat [Path] nvarchar(max),
,actiondts actionwhen ItemID int,
-- ,case TypeName nvarchar(max),
-- when lastauditid is null then dts ordinalpath nvarchar(max)
-- when r.deletestatus > 0 then ActionDTS )
-- when lastauditid = -1 then dts insert into @Chrono
-- when DeletedAuditID is not null then ActionDTS select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
-- else dts select * from @Chrono
-- end actionwhen where AuditID is null OR AuditID in (select min(auditID) from @Chrono group by contentid UNION select max(auditID) from @Chrono group by contentid)
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName order by OrdinalPath, contentid,auditid
,* --select z.* from
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --(
inner join vefn_chronologyreport(@ProcedureItemID) r --select contentid,min(auditid) auditid from
on t.icontentid = r.contentid --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) ah -- from
) x -- (
group by contentid -- select
) y -- case
inner join -- when lastauditid is null then 'Added'
( -- when r.deletestatus > 0 then 'Deleted'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath -- when lastauditid = -1 then 'Changed'
from -- when DeletedAuditID is not null then 'Restored'
( ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
select -- else 'Changed'
case -- end actionwhat
when lastauditid is null then 'Added' --,actiondts actionwhen
when r.deletestatus > 0 then 'Deleted' ---- ,case
when lastauditid = -1 then 'Changed' ---- when lastauditid is null then dts
when DeletedAuditID is not null then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when lastauditid = -1 then dts
else 'Changed' ---- when DeletedAuditID is not null then ActionDTS
end actionwhat ---- else dts
,actiondts actionwhen ---- end actionwhen
-- ,case --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when lastauditid is null then dts -- ,*
-- when r.deletestatus > 0 then ActionDTS -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when lastauditid = -1 then dts -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- when DeletedAuditID is not null then ActionDTS -- on t.icontentid = r.contentid
-- else dts ---- where ActionDTS > procdts or dts > procdts
-- end actionwhen -- ) ah
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName --) x
,* --group by contentid
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --) y
inner join vefn_chronologyreport(@ProcedureItemID) r --inner join
on t.icontentid = r.contentid --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
) ah -- from
) z on y.contentid = z.contentid and y.auditid = z.auditid -- (
union -- select
select z.* from -- case
( -- when lastauditid is null then 'Added'
select contentid,max(auditid) auditid from -- when r.deletestatus > 0 then 'Deleted'
( -- when lastauditid = -1 then 'Changed'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName -- when DeletedAuditID is not null then 'Restored'
from ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
( -- else 'Changed'
select -- end actionwhat
case --,actiondts actionwhen
when lastauditid is null then 'Added' ---- ,case
when r.deletestatus > 0 then 'Deleted' ---- when lastauditid is null then dts
when lastauditid = -1 then 'Changed' ---- when r.deletestatus > 0 then ActionDTS
when DeletedAuditID is not null then 'Restored' ---- when lastauditid = -1 then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when DeletedAuditID is not null then ActionDTS
else 'Changed' ---- else dts
end actionwhat ---- end actionwhen
,actiondts actionwhen --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,case -- ,*
-- when lastauditid is null then dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when r.deletestatus > 0 then ActionDTS -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- when lastauditid = -1 then dts -- on t.icontentid = r.contentid
-- when DeletedAuditID is not null then ActionDTS ---- where ActionDTS > procdts or dts > procdts
-- else dts -- ) ah
-- end actionwhen --) z on y.contentid = z.contentid and y.auditid = z.auditid
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName --union
,* --select z.* from
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --(
inner join vefn_chronologyreport(@ProcedureItemID) r --select contentid,max(auditid) auditid from
on t.icontentid = r.contentid --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) ah -- from
) x -- (
group by contentid -- select
) y -- case
inner join -- when lastauditid is null then 'Added'
( -- when r.deletestatus > 0 then 'Deleted'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath -- when lastauditid = -1 then 'Changed'
from -- when DeletedAuditID is not null then 'Restored'
( ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
select -- else 'Changed'
case -- end actionwhat
when lastauditid is null then 'Added' --,actiondts actionwhen
when r.deletestatus > 0 then 'Deleted' ---- ,case
when lastauditid = -1 then 'Changed' ---- when lastauditid is null then dts
when DeletedAuditID is not null then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when lastauditid = -1 then dts
else 'Changed' ---- when DeletedAuditID is not null then ActionDTS
end actionwhat ---- else dts
,actiondts actionwhen ---- end actionwhen
-- ,case --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when lastauditid is null then dts -- ,*
-- when r.deletestatus > 0 then ActionDTS -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when lastauditid = -1 then dts -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- when DeletedAuditID is not null then ActionDTS -- on t.icontentid = r.contentid
-- else dts ---- where ActionDTS > procdts or dts > procdts
-- end actionwhen -- ) ah
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName --) x
,* --group by contentid
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --) y
inner join vefn_chronologyreport(@ProcedureItemID) r --inner join
on t.icontentid = r.contentid --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
) ah -- from
) z on y.contentid = z.contentid and y.auditid = z.auditid -- (
order by OrdinalPath, contentid,auditid--actionwhen -- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) z on y.contentid = z.contentid and y.auditid = z.auditid
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
GO GO

View File

@ -2340,31 +2340,47 @@ go
-- Display the status of Trigger alter -- Display the status of Trigger alter
IF (@@Error = 0) PRINT 'Function: vefn_tblChildItems Succeeded' IF (@@Error = 0) PRINT 'Function: vefn_tblChildItems Succeeded'
ELSE PRINT 'Function: vefn_tblChildItems Error on Creation' ELSE PRINT 'Function: vefn_tblChildItems Error on Creation'
go go
/****** Object: StoredProcedure [getContentAuditsChronologyByItemID] ******/ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_GetMyChronology]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
/* DROP FUNCTION [vefn_GetMyChronology];
getContentAuditsChronologyByItemID 146,146,0 GO
getContentAuditsChronologyByItemID 30,30,0 /****** Object: UserDefinedFunction [dbo].[vefn_GetMyChronology] Script Date: 11/07/2012 18:09:17 ******/
getContentAuditsChronologyByItemID 9,9,0 SET ANSI_NULLS ON
getContentAuditsChronologyByItemID 146,146,1 GO
*/ SET QUOTED_IDENTIFIER ON
GO
/***************************************************************************** /*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved. Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/ *****************************************************************************/
CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID] CREATE FUNCTION [dbo].[vefn_GetMyChronology](@ProcItemID int, @ItemID int, @IncludeDeletedChildren int)
RETURNS @Chrono TABLE
( (
@ProcedureItemID int, [AuditID] bigint,
@SelectedItemID int, [ContentID] int,
@IncludeDeletedChildren int [Number] nvarchar(max),
[Text] nvarchar(max),
[Type] int,
[FormatID] int,
[Config] nvarchar(max),
[DTS] datetime,
[UserID] nvarchar(max),
[DeleteStatus] int,
[ActionDTS] datetime,
[ActionWhat] nvarchar(max),
[ActionWhen] datetime,
[Path] nvarchar(max),
ItemID int,
TypeName nvarchar(max),
ordinalpath nvarchar(max)
) )
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin BEGIN
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID insert into @Chrono
select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
from from
( (
select select
@ -2384,17 +2400,84 @@ begin
-- when DeletedAuditID is not null then ActionDTS -- when DeletedAuditID is not null then ActionDTS
-- else dts -- else dts
-- end actionwhen -- end actionwhen
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
,* ,*
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t from vefn_tblchilditems (@ProcItemID,@ItemID,@IncludeDeletedChildren) t
inner join vefn_chronologyreport(@ProcedureItemID) r inner join vefn_chronologyreport(@ProcItemID) r
on t.icontentid = r.contentid on t.icontentid = r.contentid
-- where ActionDTS > procdts or dts > procdts -- where ActionDTS > procdts or dts > procdts
) ah ) ah
order by OrdinalPath, contentid,auditid--actionwhen order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
END
go
IF (@@Error = 0) PRINT 'TableFunction [vefn_GetMyChronology] Succeeded'
ELSE PRINT 'TableFunction [vefn_GetMyChronology] Error on Creation'
go
/****** Object: StoredProcedure [dbo].[getContentAuditsChronologyByItemID] Script Date: 03/21/2012 15:58:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsChronologyByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getContentAuditsChronologyByItemID];
GO
/****** Object: StoredProcedure [getContentAuditsChronologyByItemID] ******/
/*
getContentAuditsChronologyByItemID 10154,10154,0
getContentAuditsChronologyByItemID 42,42,0
getContentAuditsChronologyByItemID 9,9,0
getContentAuditsChronologyByItemID 146,146,1
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
(
@ProcedureItemID int,
@SelectedItemID int,
@IncludeDeletedChildren int
)
WITH EXECUTE AS OWNER
AS
begin
select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
-- select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN
end end
go go
-- Display the status of Trigger alter -- Display the status of Proc creation
IF (@@Error = 0) PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Succeeded' IF (@@Error = 0) PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Succeeded'
ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation' ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation'
go go
@ -2625,133 +2708,161 @@ create PROCEDURE [dbo].[getContentAuditsSummaryByItemID]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin begin
DECLARE @Chrono TABLE
select z.* from
( (
select contentid,min(auditid) auditid from [AuditID] bigint,
( [ContentID] int,
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID [Number] nvarchar(max),
from [Text] nvarchar(max),
( [Type] int,
select [FormatID] int,
case [Config] nvarchar(max),
when lastauditid is null then 'Added' [DTS] datetime,
when r.deletestatus > 0 then 'Deleted' [UserID] nvarchar(max),
when lastauditid = -1 then 'Changed' [DeleteStatus] int,
when DeletedAuditID is not null then 'Restored' [ActionDTS] datetime,
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' [ActionWhat] nvarchar(max),
else 'Changed' [ActionWhen] datetime,
end actionwhat [Path] nvarchar(max),
,actiondts actionwhen ItemID int,
-- ,case TypeName nvarchar(max),
-- when lastauditid is null then dts ordinalpath nvarchar(max)
-- when r.deletestatus > 0 then ActionDTS )
-- when lastauditid = -1 then dts insert into @Chrono
-- when DeletedAuditID is not null then ActionDTS select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
-- else dts select * from @Chrono
-- end actionwhen where AuditID is null OR AuditID in (select min(auditID) from @Chrono group by contentid UNION select max(auditID) from @Chrono group by contentid)
,* order by OrdinalPath, contentid,auditid
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --select z.* from
inner join vefn_chronologyreport(@ProcedureItemID) r --(
on t.icontentid = r.contentid --select contentid,min(auditid) auditid from
-- where ActionDTS > procdts or dts > procdts --(
) ah -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) x -- from
group by contentid -- (
) y -- select
inner join -- case
( -- when lastauditid is null then 'Added'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,ordinalpath -- when r.deletestatus > 0 then 'Deleted'
from -- when lastauditid = -1 then 'Changed'
( -- when DeletedAuditID is not null then 'Restored'
select ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
case -- else 'Changed'
when lastauditid is null then 'Added' -- end actionwhat
when r.deletestatus > 0 then 'Deleted' --,actiondts actionwhen
when lastauditid = -1 then 'Changed' ---- ,case
when DeletedAuditID is not null then 'Restored' ---- when lastauditid is null then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
else 'Changed' ---- when lastauditid = -1 then dts
end actionwhat ---- when DeletedAuditID is not null then ActionDTS
,actiondts actionwhen ---- else dts
-- ,case ---- end actionwhen
-- when lastauditid is null then dts --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when r.deletestatus > 0 then ActionDTS -- ,*
-- when lastauditid = -1 then dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when DeletedAuditID is not null then ActionDTS -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- else dts -- on t.icontentid = r.contentid
-- end actionwhen ---- where ActionDTS > procdts or dts > procdts
,* -- ) ah
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --) x
inner join vefn_chronologyreport(@ProcedureItemID) r --group by contentid
on t.icontentid = r.contentid --) y
-- where ActionDTS > procdts or dts > procdts --inner join
) ah --(
) z on y.contentid = z.contentid and y.auditid = z.auditid -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
union -- from
select z.* from -- (
( -- select
select contentid,max(auditid) auditid from -- case
( -- when lastauditid is null then 'Added'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID -- when r.deletestatus > 0 then 'Deleted'
from -- when lastauditid = -1 then 'Changed'
( -- when DeletedAuditID is not null then 'Restored'
select ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
case -- else 'Changed'
when lastauditid is null then 'Added' -- end actionwhat
when r.deletestatus > 0 then 'Deleted' --,actiondts actionwhen
when lastauditid = -1 then 'Changed' ---- ,case
when DeletedAuditID is not null then 'Restored' ---- when lastauditid is null then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
else 'Changed' ---- when lastauditid = -1 then dts
end actionwhat ---- when DeletedAuditID is not null then ActionDTS
,actiondts actionwhen ---- else dts
-- ,case ---- end actionwhen
-- when lastauditid is null then dts --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when r.deletestatus > 0 then ActionDTS -- ,*
-- when lastauditid = -1 then dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when DeletedAuditID is not null then ActionDTS -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- else dts -- on t.icontentid = r.contentid
-- end actionwhen ---- where ActionDTS > procdts or dts > procdts
,* -- ) ah
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --) z on y.contentid = z.contentid and y.auditid = z.auditid
inner join vefn_chronologyreport(@ProcedureItemID) r --union
on t.icontentid = r.contentid --select z.* from
-- where ActionDTS > procdts or dts > procdts --(
) ah --select contentid,max(auditid) auditid from
) x --(
group by contentid -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) y -- from
inner join -- (
( -- select
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,ordinalpath -- case
from -- when lastauditid is null then 'Added'
( -- when r.deletestatus > 0 then 'Deleted'
select -- when lastauditid = -1 then 'Changed'
case -- when DeletedAuditID is not null then 'Restored'
when lastauditid is null then 'Added' ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
when r.deletestatus > 0 then 'Deleted' -- else 'Changed'
when lastauditid = -1 then 'Changed' -- end actionwhat
when DeletedAuditID is not null then 'Restored' --,actiondts actionwhen
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- ,case
else 'Changed' ---- when lastauditid is null then dts
end actionwhat ---- when r.deletestatus > 0 then ActionDTS
,actiondts actionwhen ---- when lastauditid = -1 then dts
-- ,case ---- when DeletedAuditID is not null then ActionDTS
-- when lastauditid is null then dts ---- else dts
-- when r.deletestatus > 0 then ActionDTS ---- end actionwhen
-- when lastauditid = -1 then dts --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when DeletedAuditID is not null then ActionDTS -- ,*
-- else dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- end actionwhen -- inner join vefn_chronologyreport(@ProcedureItemID) r
,* -- on t.icontentid = r.contentid
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t ---- where ActionDTS > procdts or dts > procdts
inner join vefn_chronologyreport(@ProcedureItemID) r -- ) ah
on t.icontentid = r.contentid --) x
-- where ActionDTS > procdts or dts > procdts --group by contentid
) ah --) y
) z on y.contentid = z.contentid and y.auditid = z.auditid --inner join
order by OrdinalPath, contentid,auditid--actionwhen --(
-- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
-- from
-- (
-- select
-- case
-- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) z on y.contentid = z.contentid and y.auditid = z.auditid
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
-- Display the status of Trigger alter -- Display the status of Trigger alter