Improved getAnnotationAuditsChronologyByItemIDandUnitID execution speed
Improved getContentAuditsChronologyByItemIDandUnitID execution speed Improved getContentAuditsSummaryByItemIDandUnitID execution speed
This commit is contained in:
parent
8d7072d3b7
commit
5302c8a95f
@ -4622,6 +4622,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'
|
||||
@ -4659,7 +4670,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
|
||||
@ -4681,7 +4692,7 @@ 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))
|
||||
and dts > @dts
|
||||
@ -4726,35 +4737,36 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemIDandUnitID]
|
||||
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
|
||||
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
|
||||
where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
order by OrdinalPath, contentid,auditid--actionwhen
|
||||
-- order by OrdinalPath, contentid,auditid--actionwhen
|
||||
RETURN
|
||||
end
|
||||
GO
|
||||
@ -4795,146 +4807,173 @@ WITH EXECUTE AS OWNER
|
||||
AS
|
||||
begin
|
||||
|
||||
select xyz.* from
|
||||
DECLARE @Chrono TABLE
|
||||
(
|
||||
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 dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
-- 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,appl,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
|
||||
,dbo.ve_GetItemApplicability(ItemID) appl
|
||||
,*
|
||||
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
|
||||
inner join vefn_chronologyreport(@ProcedureItemID) r
|
||||
on t.icontentid = r.contentid
|
||||
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
-- 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 dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
-- 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,appl,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
|
||||
,dbo.ve_GetItemApplicability(ItemID) appl
|
||||
,*
|
||||
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
|
||||
inner join vefn_chronologyreport(@ProcedureItemID) r
|
||||
on t.icontentid = r.contentid
|
||||
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
-- where ActionDTS > procdts or dts > procdts
|
||||
) ah
|
||||
) z on y.contentid = z.contentid and y.auditid = z.auditid
|
||||
) xyz
|
||||
where appl = '-1' or ',' + appl + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
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)
|
||||
where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
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 xyz.* from
|
||||
--(
|
||||
--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 dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
---- 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,appl,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
|
||||
--,dbo.ve_GetItemApplicability(ItemID) appl
|
||||
-- ,*
|
||||
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
|
||||
-- inner join vefn_chronologyreport(@ProcedureItemID) r
|
||||
-- on t.icontentid = r.contentid
|
||||
---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
---- 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 dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
---- 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,appl,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
|
||||
--,dbo.ve_GetItemApplicability(ItemID) appl
|
||||
-- ,*
|
||||
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
|
||||
-- inner join vefn_chronologyreport(@ProcedureItemID) r
|
||||
-- on t.icontentid = r.contentid
|
||||
---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
---- where ActionDTS > procdts or dts > procdts
|
||||
-- ) ah
|
||||
--) z on y.contentid = z.contentid and y.auditid = z.auditid
|
||||
--) xyz
|
||||
-- where appl = '-1' or ',' + appl + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
|
||||
-- order by OrdinalPath, contentid,auditid--actionwhen
|
||||
RETURN
|
||||
end
|
||||
GO
|
||||
|
Loading…
x
Reference in New Issue
Block a user