diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index 397b2be5..bb23434e 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -4592,3 +4592,1120 @@ IF (@@Error = 0) PRINT 'Procedure Creation: CopyItemAndChildren Succeeded' ELSE PRINT 'Procedure Creation: CopyItemAndChildren Error on Creation' GO +/****** Object: StoredProcedure [dbo].[getAnnotationAuditsChronologyByItemIDandUnitID] Script Date: 10/10/2012 14:45:33 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getAnnotationAuditsChronologyByItemIDandUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getAnnotationAuditsChronologyByItemIDandUnitID]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/****** Object: StoredProcedure [getAnnotationAuditsChronologyByItemIDandUnitID] ******/ +/* +getAnnotationAuditsChronologyByItemIDandUnitID 13,13,1 +getAnnotationAuditsChronologyByItemIDandUnitID 30,8570,1 +getAnnotationAuditsChronologyByItemIDandUnitID 1,1,1 +getAnnotationAuditsChronologyByItemIDandUnitID 30,8505,1 +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +create procedure [dbo].[getAnnotationAuditsChronologyByItemIDandUnitID] +( + @ProcItemID int, + @ItemID int, + @UnitID int +) +WITH EXECUTE AS OWNER +AS +begin + declare @dts datetime + set @dts = (select dts from items where itemid = @procitemid) + select + case + when lastauditid is null and dts > itemdts then 'Added' + when deletestatus > 0 then 'Deleted' + when lastauditid = deletedauditid then 'Restored' + else 'Changed' + end ActionWhat + ,case + when lastauditid is null and dts > itemdts then dts + when deletestatus > 0 then ActionDTS + when lastauditid = deletedauditid then ActionDTS + else dts + end ActionWhen + ,* + from + ( + select + cast(ident_current('annotationaudits') + 1 as bigint) auditid + -- (select max(auditid) + 1 from annotationaudits) auditid + -- 0 auditid + ,aa.annotationid + ,aa.itemid + ,aa.typeid + ,aa.rtftext + ,aa.searchtext + ,aa.config + ,aa.dts + ,aa.userid + ,0 deletestatus + ,aa.ActionDTS + ,ii.contentid icontentid + ,(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 vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid + where aa.deletestatus = 0 + union + select + aa.auditid + ,aa.annotationid + ,aa.itemid + ,aa.typeid + ,aa.rtftext + ,aa.searchtext + ,aa.config + ,aa.dts + ,aa.userid + ,aa.deletestatus + ,aa.ActionDTS + ,ii.contentid icontentid + ,(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 vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid + ) ah + where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0)) + and dts > @dts + and (dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%') + --(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 ordinalpath,annotationid,auditid--actionwhen +end +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getAnnotationAuditsChronologyByItemIDandUnitID Succeeded' +ELSE PRINT 'Procedure Creation: getAnnotationAuditsChronologyByItemIDandUnitID Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getContentAuditsChronologyByItemIDandUnitID] Script Date: 10/10/2012 12:48:39 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsChronologyByItemIDandUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getContentAuditsChronologyByItemIDandUnitID]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/****** Object: StoredProcedure [getContentAuditsChronologyByItemIDandUnitID] ******/ +/* +getContentAuditsChronologyByItemIDandUnitID 10154,10154,0,1 +getContentAuditsChronologyByItemIDandUnitID 42,42,0,1 +getContentAuditsChronologyByItemIDandUnitID 1,1,0,1 +getContentAuditsChronologyByItemIDandUnitID 146,146,1,1 +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemIDandUnitID] +( + @ProcedureItemID int, + @SelectedItemID int, + @IncludeDeletedChildren int, + @UnitID int +) + +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 + where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' + order by OrdinalPath, contentid,auditid--actionwhen + RETURN +end +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getContentAuditsChronologyByItemIDandUnitID Succeeded' +ELSE PRINT 'Procedure Creation: getContentAuditsChronologyByItemIDandUnitID Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getContentAuditsSummaryByItemIDandUnitID] Script Date: 10/10/2012 12:56:01 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getContentAuditsSummaryByItemIDandUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getContentAuditsSummaryByItemIDandUnitID]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +/****** Object: StoredProcedure [getContentAuditsSummaryByItemIDandUnitID] ******/ +/* +getContentAuditsSummaryByItemIDandUnitID 146,146,0,1 +getContentAuditsSummaryByItemIDandUnitID 42,42,0,1 +getContentAuditsSummaryByItemIDandUnitID 1,1,0,1 +getContentAuditsSummaryByItemIDandUnitID 146,146,1,1 +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +create PROCEDURE [dbo].[getContentAuditsSummaryByItemIDandUnitID] +( + @ProcedureItemID int, + @SelectedItemID int, + @IncludeDeletedChildren int, + @UnitID int +) + +WITH EXECUTE AS OWNER +AS +begin + +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 +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getContentAuditsSummaryByItemIDandUnitID Succeeded' +ELSE PRINT 'Procedure Creation: getContentAuditsSummaryByItemIDandUnitID Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getCurrentRevisionByItemIDandUnitID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getCurrentRevisionByItemIDandUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) +DROP PROCEDURE [dbo].[getCurrentRevisionByItemIDandUnitID]; +GO + +/****** Object: StoredProcedure [dbo].[getCurrentRevisionByItemIDandUnitID] Script Date: 06/22/2012 16:58:12 ******/ +/* +getCurrentRevisionByItemID 41 +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getCurrentRevisionByItemIDandUnitID] +( + @ItemID int, + @UnitID int +) +WITH EXECUTE AS OWNER +AS + SELECT + [Revisions].[RevisionID], + [ItemID], + [TypeID], + [RevisionNumber], + [RevisionDate], + [Notes], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(*) FROM [Checks] WHERE [Checks].[RevisionID]=[Revisions].[RevisionID]) [CheckCount], + (SELECT COUNT(*) FROM [Versions] WHERE [Versions].[RevisionID]=[Revisions].[RevisionID]) [VersionCount] + FROM [Revisions] +inner join +( +select top 1 revisionid,mxvid from +( +select rr.revisionid,max(vv.versionid) mxvid +from items ii +inner join revisions rr on ii.itemid = rr.itemid +inner join versions vv on rr.revisionid = vv.revisionid +inner join stages ss on vv.stageid = ss.stageid +cross apply rr.config.nodes('Config/Applicability') t1(r1) +where ss.isapproved = 1 +and ii.itemid = @ItemID +and r1.value('@Index','int') = @UnitID +group by rr.revisionid +union +select null,null +) ds +order by mxvid desc +) rr on [Revisions].revisionid = rr.revisionid +-- WHERE [ItemID] = @ItemID +-- ORDER BY [RevisionID] DESC + RETURN +GO +IF (@@Error = 0) PRINT 'StoredProcedure [getCurrentRevisionByItemIDandUnitID] Succeeded' +ELSE PRINT 'StoredProcedure [getCurrentRevisionByItemIDandUnitID] Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getDocumentByLibDoc] Script Date: 01/30/2012 14:08:10 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getDocumentByLibDoc]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getDocumentByLibDoc]; +GO + +-- [dbo].[getDocumentByLibDoc] 'DOC_0000',4 +-- [dbo].[getDocumentByLibDoc] 'DOC_0000',3 +-- [dbo].[getDocumentByLibDoc] 'DOC_0000',2 +-- [dbo].[getDocumentByLibDoc] 'DOC_0000',1 +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getDocumentByLibDoc] + +( + @LibDoc varchar(12), + @VersionID int +) +WITH EXECUTE AS OWNER +AS + DECLARE @DocID int + select @DocID = docid + from + ( + select + distinct ah.docid,.dbo.vefn_GetVersionIDByItemID(ii.itemid) versionid + from + ( + select dd.docid,ofn.value('@OriginalFileName','varchar(20)') origfilename,dts + from (select docid,cast(config as xml) xconfig,dts from documents) dd + cross apply xconfig.nodes('//History') t1(ofn) + ) ah + inner join entries ee on ah.docid = ee.docid + inner join items ii on ee.contentid = ii.itemid + where origfilename = @LibDoc + '.LIB' + ) ah + where versionid = @VersionID + +-- from (select docid,cast(config as xml) xconfig from documents) ah +-- cross apply xconfig.nodes('//Config/History') t1(roc) +-- where roc.value('@OriginalFileName','varchar(12)') = @LibDoc + '.LIB' + + SELECT + [DocID], + [LibTitle], + [DocContent], + [DocAscii], + [Config], + [DTS], + [UserID], + [LastChanged], + [FileExtension], + (SELECT COUNT(*) FROM [DROUsages] WHERE [DROUsages].[DocID]=[Documents].[DocID]) [DROUsageCount], + (SELECT COUNT(*) FROM [Entries] WHERE [Entries].[DocID]=[Documents].[DocID]) [EntryCount], + (SELECT COUNT(*) FROM [Pdfs] WHERE [Pdfs].[DocID]=[Documents].[DocID]) [PdfCount] + FROM [Documents] + WHERE [DocID]=@DocID + + SELECT + [DROUsages].[DROUsageID], + [DROUsages].[DocID], + [DROUsages].[ROID], + [DROUsages].[Config], + [DROUsages].[DTS], + [DROUsages].[UserID], + [DROUsages].[LastChanged], + [DROUsages].[RODbID], + [RODbs].[ROName] [RODb_ROName], + [RODbs].[FolderPath] [RODb_FolderPath], + [RODbs].[DBConnectionString] [RODb_DBConnectionString], + [RODbs].[Config] [RODb_Config], + [RODbs].[DTS] [RODb_DTS], + [RODbs].[UserID] [RODb_UserID] + FROM [DROUsages] + JOIN [RODbs] ON + [RODbs].[RODbID]=[DROUsages].[RODbID] + WHERE + [DROUsages].[DocID]=@DocID + + + SELECT + [Entries].[ContentID], + [Entries].[DocID], + [Entries].[DTS], + [Entries].[UserID], + [Entries].[LastChanged], + [Contents].[Number] [Content_Number], + [Contents].[Text] [Content_Text], + [Contents].[Type] [Content_Type], + [Contents].[FormatID] [Content_FormatID], + [Contents].[Config] [Content_Config], + [Contents].[DTS] [Content_DTS], + [Contents].[UserID] [Content_UserID] + FROM [Entries] + JOIN [Contents] ON + [Contents].[ContentID]=[Entries].[ContentID] + WHERE + [Entries].[DocID]=@DocID + + + SELECT + [Pdfs].[DocID], + [Pdfs].[DebugStatus], + [Pdfs].[TopRow], + [Pdfs].[PageLength], + [Pdfs].[LeftMargin], + [Pdfs].[PageWidth], + [Pdfs].[PageCount], + [Pdfs].[DocPdf], + [Pdfs].[DTS], + [Pdfs].[UserID], + [Pdfs].[LastChanged] + FROM [Pdfs] + WHERE + [Pdfs].[DocID]=@DocID + + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getDocumentByLibDoc Succeeded' +ELSE PRINT 'Procedure Creation: getDocumentByLibDoc Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getRevisionByItemIDandRevisionNumberAndUnitID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getRevisionByItemIDandRevisionNumberAndUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) +DROP PROCEDURE [dbo].[getRevisionByItemIDandRevisionNumberAndUnitID]; +GO + +/****** Object: StoredProcedure [dbo].[getRevisionByItemIDandRevisionNumberAndUnitID] Script Date: 06/25/2012 23:05: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].[getRevisionByItemIDandRevisionNumberAndUnitID] + +( + @ItemID int, + @RevisionNumber nvarchar(50), + @UnitID int +) +WITH EXECUTE AS OWNER +AS +declare @RevisionID int +set @RevisionID = (select revisionid from revisions rr cross apply rr.config.nodes('//Applicability') t1(r1) where itemid = @itemid and revisionnumber = @RevisionNumber and r1.value('@Index','int') = @UnitID) + SELECT + [RevisionID], + [ItemID], + [TypeID], + [RevisionNumber], + [RevisionDate], + [Notes], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(*) FROM [Checks] WHERE [Checks].[RevisionID]=[Revisions].[RevisionID]) [CheckCount], + (SELECT COUNT(*) FROM [Versions] WHERE [Versions].[RevisionID]=[Revisions].[RevisionID]) [VersionCount] + FROM [Revisions] + WHERE [RevisionID]=@RevisionID + + SELECT + [Checks].[CheckID], + [Checks].[RevisionID], + [Checks].[StageID], + [Checks].[ConsistencyChecks], + [Checks].[DTS], + [Checks].[UserID], + [Checks].[LastChanged], + [Stages].[Name] [Stage_Name], + [Stages].[Description] [Stage_Description], + [Stages].[IsApproved] [Stage_IsApproved], + [Stages].[DTS] [Stage_DTS], + [Stages].[UserID] [Stage_UserID] + FROM [Checks] + JOIN [Stages] ON + [Stages].[StageID]=[Checks].[StageID] + WHERE + [Checks].[RevisionID]=@RevisionID + + + SELECT + [Versions].[VersionID], + [Versions].[RevisionID], + [Versions].[StageID], + [Versions].[DTS], + [Versions].[UserID], + [Versions].[LastChanged], + [Versions].[PDF], + [Versions].[SummaryPDF], + [Stages].[Name] [Stage_Name], + [Stages].[Description] [Stage_Description], + [Stages].[IsApproved] [Stage_IsApproved], + [Stages].[DTS] [Stage_DTS], + [Stages].[UserID] [Stage_UserID] + FROM [Versions] + JOIN [Stages] ON + [Stages].[StageID]=[Versions].[StageID] + WHERE + [Versions].[RevisionID]=@RevisionID + + RETURN +GO +IF (@@Error = 0) PRINT 'StoredProcedure [getRevisionByItemIDandRevisionNumberAndUnitID] Succeeded' +ELSE PRINT 'StoredProcedure [getRevisionByItemIDandRevisionNumberAndUnitID] Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[getRevisionsByItemIDandUnitID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getRevisionsByItemIDandUnitID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) +DROP PROCEDURE [dbo].[getRevisionsByItemIDandUnitID]; +GO + +/****** Object: StoredProcedure [dbo].[getRevisionsByItemIDandUnitID] Script Date: 06/26/2012 16:22:32 ******/ +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].[getRevisionsByItemIDandUnitID] +( + @ItemID int, + @UnitID int +) +WITH EXECUTE AS OWNER +AS + SELECT + [RevisionID], + [ItemID], + [TypeID], + [RevisionNumber], + [RevisionDate], + [Notes], + [Config], + [DTS], + [UserID], + [LastChanged], + (SELECT COUNT(*) FROM [Checks] WHERE [Checks].[RevisionID]=[Revisions].[RevisionID]) [CheckCount], + (SELECT COUNT(*) FROM [Versions] WHERE [Versions].[RevisionID]=[Revisions].[RevisionID]) [VersionCount] + FROM [Revisions] +cross apply config.nodes('//Applicability') t1(r1) + WHERE [ItemID] = @ItemID +and r1.value('@Index','int') = @UnitID + ORDER BY [RevisionID] DESC + RETURN +GO +IF (@@Error = 0) PRINT 'StoredProcedure [getRevisionsByItemIDandUnitID] Succeeded' +ELSE PRINT 'StoredProcedure [getRevisionsByItemIDandUnitID] Error on Creation' +GO + +/****** Object: UserDefinedFunction [dbo].[vefn_GetItemApplicability] Script Date: 03/28/2012 17:58:48 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetItemApplicability]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [ve_GetItemApplicability]; +GO +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[ve_GetItemApplicability] (@ItemID int) RETURNS varchar(max) +WITH EXECUTE AS OWNER +AS +BEGIN +declare @apple varchar(max) +select @apple = isnull(r2.value('@Applicability','varchar(max)'),'-1') +from +( +select itemid,cast(config as xml) xconfig from items ii join contents cc on ii.contentid = cc.contentid +) t1 +outer apply xconfig.nodes('//MasterSlave') t2(r2) +where itemid = @ItemID +if @apple = '-1' begin + set @apple = '' + select @apple = coalesce(@apple + ',','') + r2.value('@index','varchar(max)') from + (select cast(config as xml) xconfig from docversions + where versionid = dbo.vefn_GetVersionIDByItemID(@ItemID)) ah + cross apply xconfig.nodes('//Slave') t2(r2) + set @apple = substring(@apple,2,len(@apple)) +end +return @apple +END +GO +IF (@@Error = 0) PRINT 'ScalerFunction [vefn_GetItemApplicability] Succeeded' +ELSE PRINT 'ScalerFunction [vefn_GetItemApplicability] Error on Creation' +go + +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetItemDerivedApplicability]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [ve_GetItemDerivedApplicability]; +GO + +/****** Object: UserDefinedFunction [dbo].[ve_GetItemDerivedApplicability] Script Date: 10/13/2012 00:57:34 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +select [dbo].[ve_GetItemDerivedApplicability](48) +select [dbo].[ve_GetItemDerivedApplicability](49) +select [dbo].[ve_GetItemDerivedApplicability](50) +select [dbo].[ve_GetItemDerivedApplicability](51) +select [dbo].[ve_GetItemDerivedApplicability](52) +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[ve_GetItemDerivedApplicability] (@ItemID int) RETURNS varchar(max) +WITH EXECUTE AS OWNER +AS +BEGIN + declare @apple varchar(max) + set @apple = '' + select @apple = @apple + ',' + cast(id as varchar(10)) + from [dbo].[vefn_ParentItems](@ItemID) + cross apply vefn_SplitInt([dbo].[ve_GetItemApplicability](itemid),',') + where [dbo].[ve_GetItemApplicability](itemid) != '-1' + group by id having count(*) = (select count(*) from [dbo].[vefn_ParentItems](@ItemID) where [dbo].[ve_GetItemApplicability](itemid) != '-1') + return substring(@apple,2,len(@apple)) +END +GO +-- Display the status of TableFunction creation +IF (@@Error = 0) PRINT 'Function: ve_GetItemDerivedApplicability Succeeded' +ELSE PRINT 'Function: ve_GetItemDerivedApplicability Error on Creation' +GO + +/****** Object: UserDefinedFunction [dbo].[vefn_GetParentItem] Script Date: 03/28/2012 17:58:48 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetParentItem]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [ve_GetParentItem]; +GO +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[ve_GetParentItem] (@ItemID int) RETURNS int +WITH EXECUTE AS OWNER +AS +BEGIN +DECLARE @ParentID int; +WITH Itemz([ItemID],[IsFound]) as +( +select ii.itemid,0 from items ii where ii.itemid = @ItemID +union all +select ii.previousid,0 from items ii +join itemz zz on ii.itemid = zz.itemid +where ii.previousid is not null +and zz.isfound = 0 +union all +select ii.itemid,1 +from parts pp +join itemz zz on pp.itemid = zz.itemid +join items ii on ii.contentid = pp.contentid +) +select top 1 @ParentID = itemid from itemz +where isfound = 1 +RETURN @ParentID +END +GO + +IF (@@Error = 0) PRINT 'ScalerFunction [vefn_GetParentItem] Succeeded' +ELSE PRINT 'ScalerFunction [vefn_GetParentItem] Error on Creation' +go + +/****** Object: UserDefinedFunction [dbo].[vefn_CanTransitionBeCreated] Script Date: 10/14/2012 02:03:30 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_CanTransitionBeCreated]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_CanTransitionBeCreated]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +select dbo.vefn_CanTransitionBeCreated(49,51) +select dbo.vefn_CanTransitionBeCreated(51,49) +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[vefn_CanTransitionBeCreated](@fromID int, @toID int) RETURNS int +AS BEGIN + declare @rv int + declare @tCount int + declare @uCount int + set @rv = 0 + select @tCount = count(*) from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@toID),',') + select @uCount = count(*) from + ( + select * from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@fromID),',') + union + select * from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@toID),',') + ) ah + if @tCount >= @uCount begin + set @rv = 1 + end + return @rv +END +GO +-- Display the status of TableFunction creation +IF (@@Error = 0) PRINT 'Function: vefn_CanTransitionBeCreated Succeeded' +ELSE PRINT 'Function: vefn_CanTransitionBeCreated Error on Creation' +GO + +/****** Object: UserDefinedFunction [dbo].[vefn_GetVersionIDByItemID] Script Date: 02/03/2012 16:48:32 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_GetVersionIDByItemID]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_GetVersionIDByItemID]; +GO + +/* +select dbo.vefn_GetVersionIDByItemID(41) +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +create function [dbo].[vefn_GetVersionIDByItemID] +(@ItemID int) +returns int +as begin + declare @VersionID int; + with itemz + ( + itemid,previousid,versionid + ) as + ( + select itemid,previousid,null + from items ii + join contents cc on ii.contentid = cc.contentid + where itemid = @ItemID + --siblins + union all + select ii.itemid,ii.previousid,null + from items ii + join contents cc on ii.contentid = cc.contentid + join itemz zz on zz.previousid = ii.itemid + where zz.versionid is null + --chillins + union all + select ii.itemid,ii.previousid,null + from parts pp + join items ii on ii.contentid = pp.contentid + join contents cc on ii.contentid = cc.contentid + join itemz zz on zz.itemid = pp.itemid + where zz.versionid is null + --docversions + union all + select 0,0,dv.versionid + from docversions dv + join itemz zz on dv.itemid = zz.itemid + where zz.versionid is null + ) + select @VersionID = versionid from itemz zz + where versionid is not null + OPTION (MAXRECURSION 10000) + return @VersionID +end +GO +-- Display the status of Func creation +IF (@@Error = 0) PRINT 'Function Creation: vefn_GetVersionIDByItemID Succeeded' +ELSE PRINT 'Function Creation: vefn_GetVersionIDByItemID Error on Creation' +GO + +/****** Object: UserDefinedFunction [dbo].[vefn_WillTransitionBeValidFrom] Script Date: 10/16/2012 18:17:37 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_WillTransitionBeValidFrom]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_WillTransitionBeValidFrom]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +select dbo.vefn_WillTransitionBeValidFrom(194,'2') +select dbo.vefn_WillTransitionBeValidFrom(216,'2') +select dbo.vefn_WillTransitionBeValidFrom(246,'2') +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[vefn_WillTransitionBeValidFrom](@toID int, @newAppl varchar(max)) RETURNS int +AS BEGIN + declare @rv int + declare @tCount int + declare @uCount int + set @rv = 0 + select @tCount = count(*) from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@toID),',') + select @uCount = count(*) from + ( + select * from vefn_SplitInt(@newAppl,',') + union + select * from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@toID),',') + ) ah + if @tCount >= @uCount begin + set @rv = 1 + end + return @rv +END +GO +-- Display the status of TableFunction creation +IF (@@Error = 0) PRINT 'Function: vefn_WillTransitionBeValidFrom Succeeded' +ELSE PRINT 'Function: vefn_WillTransitionBeValidFrom Error on Creation' +GO + +/****** Object: UserDefinedFunction [dbo].[vefn_WillTransitionBeValidTo] Script Date: 10/16/2012 18:20:23 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_WillTransitionBeValidTo]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_WillTransitionBeValidTo]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +select dbo.vefn_WillTransitionBeValidTo(10617,'2') +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE FUNCTION [dbo].[vefn_WillTransitionBeValidTo](@toID int, @newAppl varchar(max)) RETURNS int +AS BEGIN + declare @rv int + declare @tCount int + declare @uCount int + set @rv = 0 + select @tCount = count(*) from vefn_SplitInt(@newAppl,',') + select @uCount = count(*) from + ( + select * from vefn_SplitInt(@newAppl,',') + union + select * from vefn_SplitInt([dbo].[ve_GetItemDerivedApplicability](@toID),',') + ) ah + if @tCount >= @uCount begin + set @rv = 1 + end + return @rv +END +GO +-- Display the status of TableFunction creation +IF (@@Error = 0) PRINT 'Function: vefn_WillTransitionBeValidTo Succeeded' +ELSE PRINT 'Function: vefn_WillTransitionBeValidTo Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[vesp_CanTransitionBeCreated] Script Date: 10/15/2012 14:37:32 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_CanTransitionBeCreated]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_CanTransitionBeCreated]; +GO +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +exec vesp_CanTransitionBeCreated 46,180 +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[vesp_CanTransitionBeCreated] +( + @fromItemID int, + @toItemID int +) +AS BEGIN + select dbo.vefn_CanTransitionBeCreated(@fromItemID,@toItemID) Status, + dbo.ve_GetItemDerivedApplicability(@fromItemID) fromAppl, + dbo.ve_GetItemDerivedApplicability(@toItemID) toAppl, + dbo.ve_GetShortPath(@fromItemID) fromStep, + dbo.ve_GetShortPath(@toItemID) toStep +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_CanTransitionBeCreated Succeeded' +ELSE PRINT 'Procedure Creation: vesp_CanTransitionBeCreated Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[vesp_ListItemAndChildrenByUnit] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[vesp_ListItemAndChildrenByUnit]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) +DROP PROCEDURE [dbo].[vesp_ListItemAndChildrenByUnit]; +GO + +/****** Object: StoredProcedure [dbo].[vesp_ListItemAndChildrenByUnit] Script Date: 05/02/2012 23:16:53 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- vesp_ListItemAndChildren 1,0 +-- drop procedure [vesp_ListItemAndChildren] +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[vesp_ListItemAndChildrenByUnit] (@ItemID int, @ParentID int, @UnitID varchar(max)) +WITH EXECUTE AS OWNER +AS +BEGIN +with Itemz([apple],[Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [FromType], [ContentID], [DTS], [UserID], [LastChanged],[pContentID], [pDTS],[pUserID],[pLastChanged]) as ( + Select 1 [apple],0 [Level], @ParentID [ParentID], 0 [Ordinal], [ItemID], [PreviousID],0 [FromType],[ContentID],[DTS],[UserID],[LastChanged] + ,0 [pContentID],[DTS] [pDTS], [UserID] [pUserID], [LastChanged] [pLastChanged] + FROM [Items] + where [ItemID]=@ItemID +Union All +-- Children + select case when s1.value('@Applicability','varchar(max)') is null or ',' + s1.value('@Applicability','varchar(max)') + ',' like '%,' + @UnitID + ',%' then 1 else 0 end apple +,[Level] + 1,Z.ItemID,0, I.[ItemID], I.[PreviousID], P.[FromType],I.[ContentID],I.[DTS],I.[UserID],I.[LastChanged] + ,P.[ContentID] [pContentID],P.[DTS] [pDTS],P.[UserID] [pUserID],P.[LastChanged] [pLastChanged] + from Itemz Z + join Parts P on P.ContentID = Z.ContentID + join Items I on I.ItemID = P.ItemID + join (select ContentID,cast(Config as xml) xConfig from Contents) C on C.ContentID = I.ContentID + outer apply C.xConfig.nodes('//MasterSlave') m1(s1) +where Z.[Apple] = 1 +-- Siblings +Union All + select case when s1.value('@Applicability','varchar(max)') is null or ',' + s1.value('@Applicability','varchar(max)') + ',' like '%,' + @UnitID + ',%' then 1 else 0 end apple +,[Level] ,Z.[ParentID], +case when Z.[Apple] = 1 then Z.[Ordinal] +1 else Z.[Ordinal] end, I.[ItemID], +case when Z.[Apple] = 1 then I.[PreviousID] else Z.[PreviousID] end, [FromType],I.[ContentID],I.[DTS],I.[UserID],I.[LastChanged] + ,null,null,null,null + from Itemz Z + join Items I on I.PreviousID = Z.ItemID + join (select ContentID,cast(Config as xml) xConfig from Contents) C on C.ContentID = I.ContentID + outer apply C.xConfig.nodes('//MasterSlave') m1(s1) + where Z.[Level] > 0 +) +select I.[Level],I.[FromType],I.[Ordinal], I.[ParentID], I.[ItemID],I.[PreviousID],I.[ContentID],I.[DTS],I.[UserID],I.[LastChanged], + C.[Number],C.[Text],C.[Type],C.[FormatID],C.[Config],C.[DTS] [cDTS],C.[UserID] [cUserID],C.[LastChanged] [cLastChanged], + [pContentID],[pDTS],[pUserID],[pLastChanged], + (SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[ItemID]=[I].[ItemID]) [AnnotationCount], + (SELECT COUNT(*) FROM [DocVersions] WHERE [DocVersions].[ItemID]=[I].[ItemID]) [DocVersionCount], + (SELECT COUNT(*) FROM [Items] [Next] WHERE [Next].[PreviousID]=[I].[ItemID]) [NextCount], + (SELECT COUNT(*) FROM [Parts] WHERE [Parts].[ItemID]=[I].[ItemID]) [PartCount], + (SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[RangeID]=[I].[ItemID]) [Transition_RangeIDCount], + (SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[ToID]=[I].[ItemID]) [Transition_ToIDCount], + (SELECT COUNT(*) FROM [Details] WHERE [Details].[ContentID]=[C].[ContentID]) [DetailCount], + (SELECT COUNT(*) FROM [Entries] WHERE [Entries].[ContentID]=[C].[ContentID]) [EntryCount], + (SELECT COUNT(*) FROM [Grids] WHERE [Grids].[ContentID]=[C].[ContentID]) [GridCount], + (SELECT COUNT(*) FROM [Images] WHERE [Images].[ContentID]=[C].[ContentID]) [ImageCount], + (SELECT COUNT(*) FROM [Items] WHERE [Items].[ContentID]=[C].[ContentID]) [ItemCount], + (SELECT COUNT(*) FROM [Parts] WHERE [Parts].[ContentID]=[C].[ContentID]) [cPartCount], + (SELECT COUNT(*) FROM [RoUsages] WHERE [RoUsages].[ContentID]=[C].[ContentID]) [RoUsageCount], + (SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[FromID]=[C].[ContentID]) [TransitionCount], + (SELECT COUNT(*) FROM [ZContents] WHERE [ZContents].[ContentID]=[C].[ContentID]) [ZContentCount] + from ItemZ I + join Contents C on C.ContentID = I.ContentID +where i.apple = 1 + order by I.[Level] , I.[FromType], I.[Ordinal] +END +GO +-- Display the status of Procedure Creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_ListItemAndChildrenByUnit Succeeded' +ELSE PRINT 'Procedure Creation: vesp_ListItemAndChildrenByUnit Error on Creation' +GO + +/****** Object: StoredProcedure [dbo].[vesp_WillTransitionsBeValid] Script Date: 10/15/2012 14:37:32 ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_WillTransitionsBeValid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_WillTransitionsBeValid]; +GO +/* +dbo.vesp_WillTransitionsBeValid 10616,'2' +*/ +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE vesp_WillTransitionsBeValid +( + @ItemID int, + @NewAppl varchar(max) +) +AS BEGIN + select *, dbo.ve_GetShortPath(@ItemID) SrcStep, dbo.ve_GetShortPath(myitemid) TgtStep + from + ( + select tt.toid MyItemID, dbo.vefn_WillTransitionBeValidFrom(tt.toid,@NewAppl) Valid, @NewAppl SrcAppl, dbo.ve_GetItemDerivedApplicability(tt.toid) TgtAppl + from transitions tt + inner join items ii on tt.fromid = ii.contentid + where fromid in (select contentid from dbo.vefn_childitems(@ItemID)) + union + select ii.itemid MyItemID, dbo.vefn_WillTransitionBeValidTo(ii.itemid,@NewAppl) Valid, dbo.ve_GetItemDerivedApplicability(ii.itemid) SrcAppl, @NewAppl TgtAppl + from transitions tt + inner join items ii on tt.fromid = ii.contentid + where toid in (select itemid from dbo.vefn_childitems(@ItemID)) + ) ah + where Valid = 0 +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_WillTransitionsBeValid Succeeded' +ELSE PRINT 'Procedure Creation: vesp_WillTransitionsBeValid Error on Creation' +GO