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'
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 ******/
SET ANSI_NULLS ON
GO
@ -622,34 +695,35 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
WITH EXECUTE AS OWNER
AS
begin
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
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
go
@ -658,6 +732,195 @@ IF (@@Error = 0) PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Suc
ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation'
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)
DROP FUNCTION [vefn_FixSearchString];
GO
@ -1053,6 +1316,17 @@ AS
begin
declare @dts datetime
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
case
when lastauditid is null and dts > itemdts then 'Added'
@ -1090,7 +1364,7 @@ begin
,tci.ordinalpath
from tblannotations aa
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
union
select
@ -1112,9 +1386,9 @@ join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid
,tci.ordinalpath
from annotationaudits aa
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
where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0))
where itemid in (select itemid from @tci)
and dts > @dts
--(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))

View File

@ -703,6 +703,17 @@ AS
begin
declare @dts datetime
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
case
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 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
,tci.ordinalpath
from tblannotations aa
inner join items ii on aa.itemid = ii.itemid
join @tci tci on tci.itemid = ii.itemid
where aa.deletestatus = 0
union
select
@ -757,14 +770,16 @@ begin
,(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 and deletestatus > 0 and aa.dts = dts) DeletedAuditID
,tci.ordinalpath
from annotationaudits aa
inner join items ii on aa.itemid = ii.itemid
join @tci tci on tci.itemid = ii.itemid
) ah
where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0))
where itemid in (select itemid from @tci)
and dts > @dts
--(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))
order by annotationid,auditid--actionwhen
order by ordinalpath,annotationid,auditid--actionwhen
end
GO
-- 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'
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] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsChronologyByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getContentAuditsChronologyByItemID];
@ -1034,34 +1122,35 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
WITH EXECUTE AS OWNER
AS
begin
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
order by OrdinalPath, contentid,auditid--actionwhen
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
GO
@ -1096,137 +1185,161 @@ CREATE PROCEDURE [dbo].[getContentAuditsSummaryByItemID]
WITH EXECUTE AS OWNER
AS
begin
select z.* from
DECLARE @Chrono TABLE
(
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
[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

View File

@ -2340,31 +2340,47 @@ go
-- Display the status of Trigger alter
IF (@@Error = 0) PRINT 'Function: vefn_tblChildItems Succeeded'
ELSE PRINT 'Function: vefn_tblChildItems Error on Creation'
go
/****** Object: StoredProcedure [getContentAuditsChronologyByItemID] ******/
/*
getContentAuditsChronologyByItemID 146,146,0
getContentAuditsChronologyByItemID 30,30,0
getContentAuditsChronologyByItemID 9,9,0
getContentAuditsChronologyByItemID 146,146,1
*/
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 PROCEDURE [dbo].[getContentAuditsChronologyByItemID]
CREATE FUNCTION [dbo].[vefn_GetMyChronology](@ProcItemID int, @ItemID int, @IncludeDeletedChildren int)
RETURNS @Chrono TABLE
(
@ProcedureItemID int,
@SelectedItemID int,
@IncludeDeletedChildren int
[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
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID
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
@ -2384,17 +2400,84 @@ begin
-- 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
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 ******/
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
go
-- Display the status of Trigger alter
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Succeeded'
ELSE PRINT 'StoredProcedure [getContentAuditsChronologyByItemID] Error on Creation'
go
@ -2625,133 +2708,161 @@ create PROCEDURE [dbo].[getContentAuditsSummaryByItemID]
WITH EXECUTE AS OWNER
AS
begin
select z.* from
DECLARE @Chrono TABLE
(
select contentid,min(auditid) auditid from
(
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID
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
,*
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,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
,*
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
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
,*
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,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
,*
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
[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
-- Display the status of Trigger alter