PROMSFixes.Sql - Changed logic in Stored Procedures and functions to Properly format PATH when the Procedure Number includes a Decimal Point
vefn_SiblingAndChildrenItems vesp_SearchItemAndChildren vesp_GetROUsagesByProcedure vesp_SearchROItemAndChildren vefn_SiblingAndChildrenItemsByProc Removed duplicate vesp_SearchROItemAndChildren
This commit is contained in:
parent
f81483df52
commit
eed947c044
@ -1234,7 +1234,7 @@ Union All
|
|||||||
PPath + case C.Type/10000
|
PPath + case C.Type/10000
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text -- Procedure
|
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text -- Procedure
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text -- Section
|
when 1 then @Delim + C.Number + @DelimNumber + C.Text -- Section
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
end Path, 0,
|
end Path, 0,
|
||||||
POrdinalPath,
|
POrdinalPath,
|
||||||
POrdinalPath + right('00000' + cast(Z.[Ordinal] + 2 as varchar(5)), 5), UnitPrefix
|
POrdinalPath + right('00000' + cast(Z.[Ordinal] + 2 as varchar(5)), 5), UnitPrefix
|
||||||
@ -1376,7 +1376,7 @@ Union All
|
|||||||
PPath + case C.Type/10000
|
PPath + case C.Type/10000
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
end Path, 0,
|
end Path, 0,
|
||||||
POrdinalPath,
|
POrdinalPath,
|
||||||
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
||||||
@ -1514,7 +1514,7 @@ Union All
|
|||||||
PPath + case C.Type/10000
|
PPath + case C.Type/10000
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
end Path, 0,
|
end Path, 0,
|
||||||
POrdinalPath,
|
POrdinalPath,
|
||||||
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
||||||
@ -1568,141 +1568,6 @@ IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SearchItemAndChildren Succeeded
|
|||||||
ELSE PRINT 'Procedure Creation: vesp_SearchItemAndChildren Error on Creation'
|
ELSE PRINT 'Procedure Creation: vesp_SearchItemAndChildren Error on Creation'
|
||||||
GO
|
GO
|
||||||
|
|
||||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SearchROItemAndChildren]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
|
||||||
DROP PROCEDURE [vesp_SearchROItemAndChildren];
|
|
||||||
GO
|
|
||||||
/*
|
|
||||||
exec vesp_SearchROItemAndChildren '1,2,4','20007','1:00010000019C,0001000002AE'
|
|
||||||
exec vesp_SearchROItemAndChildren '1,2,4','','1:00010000019C,0001000002AE'
|
|
||||||
exec vesp_SearchROItemAndChildren '1,2,4','20007','1:0001'
|
|
||||||
exec vesp_SearchROItemAndChildren '1,2,4','20006','1'
|
|
||||||
exec vesp_SearchROItemAndChildren '1,2,4','20006',''
|
|
||||||
exec vesp_SearchROItemAndChildren '',Null,Null,'XXX-'
|
|
||||||
*/
|
|
||||||
CREATE PROCEDURE [dbo].[vesp_SearchROItemAndChildren] (@DocVersionList varchar(MAX), @StepTypeList varchar(MAX), @ROSearchString varchar(MAX), @UnitPrefix as varchar(MAX))
|
|
||||||
WITH EXECUTE AS OWNER
|
|
||||||
AS
|
|
||||||
BEGIN
|
|
||||||
Declare @Delim char(1)
|
|
||||||
Set @Delim=char(7)
|
|
||||||
Declare @DelimNumber char(1)
|
|
||||||
Set @DelimNumber=char(17)
|
|
||||||
Declare @DelimStep char(1)
|
|
||||||
Set @DelimStep='.'
|
|
||||||
begin
|
|
||||||
with Itemz(DVPath, [Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [FromType], [ContentID], [DTS], [UserID], [LastChanged],[pContentID],
|
|
||||||
[pDTS],[pUserID],[pLastChanged],PPath, Path, IsRNO, POrdinalPath, OrdinalPath, UnitPrefix) as (
|
|
||||||
Select DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [I].[ItemID], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID],[I].[LastChanged]
|
|
||||||
,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID], [I].[LastChanged] [pLastChanged],
|
|
||||||
Cast('' as nvarchar(max)) PPath,
|
|
||||||
Cast(Case when C.Type < 20000 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text else '1' end as nvarchar(max)) Path,
|
|
||||||
0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix
|
|
||||||
|
|
||||||
FROM [Items] I
|
|
||||||
Join Contents C on C.ContentID=I.ContentID
|
|
||||||
JOIN vefn_DocVersionSplit(@DocVersionList) DV
|
|
||||||
ON I.[ItemID] = DV.[ItemID]
|
|
||||||
Union All
|
|
||||||
-- Children
|
|
||||||
select DVPath, [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]
|
|
||||||
,PATH + --''
|
|
||||||
case C.Type/10000
|
|
||||||
when 2 then
|
|
||||||
case P.FromType
|
|
||||||
when 3 then @DelimStep + 'Caution'
|
|
||||||
when 4 then @DelimStep + 'Note'
|
|
||||||
else '' end
|
|
||||||
else '' end
|
|
||||||
PPath,
|
|
||||||
--Path + case when Z.FromType < 3 then @Delim else @DelimStep end + case C.Type/10000
|
|
||||||
Path + case C.Type/10000
|
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
|
||||||
else
|
|
||||||
case P.FromType
|
|
||||||
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
|
|
||||||
--when 2 then 'SEC' + @Delim + cast(1 as varchar(3))
|
|
||||||
when 3 then @DelimStep +'Caution' + @DelimStep + cast(1 as varchar(3))
|
|
||||||
when 4 then @DelimStep +'Note' + @DelimStep + cast(1 as varchar(3))
|
|
||||||
when 5 then @DelimStep +'RNO' + @DelimStep
|
|
||||||
when 7 then @DelimStep +'Table' + @DelimStep
|
|
||||||
else case when Z.FromType < 3 then @Delim else @DelimStep end + cast(1 as varchar(3))
|
|
||||||
end end Path,
|
|
||||||
case when P.FromType = 5 then -1 else 0 end IsRNO,
|
|
||||||
OrdinalPath + '.' + Right('0000' + Cast(P.FromType as varchar(4)), 4) + '-' ,
|
|
||||||
OrdinalPath + '.' + Right('0000' + Cast(P.FromType as varchar(4)), 4) + '-0001', UnitPrefix
|
|
||||||
from Itemz Z
|
|
||||||
join Parts P on P.ContentID = Z.ContentID
|
|
||||||
join Items I on I.ItemID = P.ItemID
|
|
||||||
join Contents C on C.ContentID = I.ContentID
|
|
||||||
Union All
|
|
||||||
-- Siblings
|
|
||||||
select DVPath, [Level] ,Z.[ParentID],Z.[Ordinal] +1, I.[ItemID], I.[PreviousID], [FromType],I.[ContentID],I.[DTS],I.[UserID],I.[LastChanged]
|
|
||||||
,null,null,null,null
|
|
||||||
,PPath,
|
|
||||||
--'1' +
|
|
||||||
PPath + case C.Type/10000
|
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
|
||||||
end Path, 0,
|
|
||||||
POrdinalPath,
|
|
||||||
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
|
||||||
from Itemz Z
|
|
||||||
join Items I on I.PreviousID = Z.ItemID
|
|
||||||
join Contents C on C.ContentID = I.ContentID
|
|
||||||
--where Z.[Level] > 0
|
|
||||||
)
|
|
||||||
select DvPath, Path, 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
|
|
||||||
left join Entries E on C.ContentID = E.ContentID
|
|
||||||
left join Documents D on E.DocID = D.DocID
|
|
||||||
where
|
|
||||||
I.ContentID in(select ContentID from ROUsages RU
|
|
||||||
join vefn_SplitROSearch(@ROSearchString) RR
|
|
||||||
ON RR.RODBID = RU.RODBID and
|
|
||||||
RU.ROID like RR.ROID + '%' Collate SQL_Latin1_General_CP1_CI_AS
|
|
||||||
UNION
|
|
||||||
select Distinct ContentID from Entries EE
|
|
||||||
Join DROUsages RU on RU.DocID = EE.DocID
|
|
||||||
join vefn_SplitROSearch(@ROSearchString) RR
|
|
||||||
ON RR.RODBID = RU.RODBID and
|
|
||||||
RU.ROID = RR.ROID)
|
|
||||||
AND
|
|
||||||
((isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
|
|
||||||
or
|
|
||||||
((dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))
|
|
||||||
or
|
|
||||||
(@StepTypeList like '%20040%' AND IsRNO = -1)))
|
|
||||||
order by DvPath,OrdinalPath
|
|
||||||
OPTION (MAXRECURSION 10000)
|
|
||||||
END
|
|
||||||
END
|
|
||||||
GO
|
|
||||||
-- Display the status of Proc creation
|
|
||||||
IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SearchROItemAndChildren Succeeded'
|
|
||||||
ELSE PRINT 'Procedure Creation: vesp_SearchROItemAndChildren Error on Creation'
|
|
||||||
GO
|
|
||||||
|
|
||||||
/****** Object: StoredProcedure [vesp_SearchItemAndChildrenNew] ******/
|
/****** Object: StoredProcedure [vesp_SearchItemAndChildrenNew] ******/
|
||||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SearchItemAndChildrenNew]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SearchItemAndChildrenNew]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
||||||
DROP PROCEDURE [vesp_SearchItemAndChildrenNew];
|
DROP PROCEDURE [vesp_SearchItemAndChildrenNew];
|
||||||
@ -1881,7 +1746,7 @@ Union All
|
|||||||
PPath + case C.Type/10000
|
PPath + case C.Type/10000
|
||||||
when 0 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text
|
when 0 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text
|
||||||
when 1 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text
|
when 1 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
end Path, 0,
|
end Path, 0,
|
||||||
POrdinalPath,
|
POrdinalPath,
|
||||||
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4),
|
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4),
|
||||||
@ -2058,7 +1923,7 @@ Union All
|
|||||||
PPath + case C.Type/10000
|
PPath + case C.Type/10000
|
||||||
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text
|
||||||
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
||||||
else case when Path like '%.%' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
end Path, 0,
|
end Path, 0,
|
||||||
POrdinalPath,
|
POrdinalPath,
|
||||||
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
POrdinalPath + right('0000' + cast(Z.[Ordinal] + 2 as varchar(4)), 4), UnitPrefix
|
||||||
@ -2290,3 +2155,123 @@ GO
|
|||||||
IF (@@Error = 0) PRINT 'Procedure Creation: vesp_ListItemsTranToAndContent Succeeded'
|
IF (@@Error = 0) PRINT 'Procedure Creation: vesp_ListItemsTranToAndContent Succeeded'
|
||||||
ELSE PRINT 'Procedure Creation: vesp_ListItemsTranToAndContent Error on Creation'
|
ELSE PRINT 'Procedure Creation: vesp_ListItemsTranToAndContent Error on Creation'
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
/****** Object: StoredProcedure [vefn_SiblingAndChildrenItemsByProc] ******/
|
||||||
|
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_SiblingAndChildrenItemsByProc]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
|
||||||
|
DROP FUNCTION [vefn_SiblingAndChildrenItemsByProc];
|
||||||
|
GO
|
||||||
|
|
||||||
|
/****** Object: UserDefinedFunction [dbo].[vefn_tblChildItems] Script Date: 05/18/2011 11:20:48 ******/
|
||||||
|
/*
|
||||||
|
select * from vefn_SiblingAndChildrenItemsByProc(30) II
|
||||||
|
join
|
||||||
|
*/
|
||||||
|
|
||||||
|
CREATE FUNCTION [dbo].[vefn_SiblingAndChildrenItemsByProc](@ProcID int)
|
||||||
|
RETURNS @SiblingAndChildren TABLE
|
||||||
|
(
|
||||||
|
[ItemID] int PRIMARY KEY
|
||||||
|
, [DVPath] nvarchar(max)
|
||||||
|
, [Path] nvarchar(max)
|
||||||
|
, [Level] int
|
||||||
|
, [FromType] int
|
||||||
|
, [Ordinal] int
|
||||||
|
, [ParentID] int
|
||||||
|
, [PreviousID] int
|
||||||
|
, [ContentID] int
|
||||||
|
, [DTS] datetime
|
||||||
|
, [UserID] nvarchar(100)
|
||||||
|
, [pContentID] int
|
||||||
|
, [pDTS] datetime
|
||||||
|
, [pUserID] nvarchar(100)
|
||||||
|
, [IsRNO] int
|
||||||
|
|
||||||
|
-- , [PPath] nvarchar(max)
|
||||||
|
-- , [POrdinalPath] nvarchar(max)
|
||||||
|
, [OrdinalPath] nvarchar(max)
|
||||||
|
)
|
||||||
|
WITH EXECUTE AS OWNER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
Declare @Delim char(1)
|
||||||
|
Set @Delim=char(7)
|
||||||
|
Declare @DelimNumber char(1)
|
||||||
|
Set @DelimNumber=char(17)
|
||||||
|
Declare @DelimStep char(1)
|
||||||
|
Set @DelimStep='.'
|
||||||
|
BEGIN
|
||||||
|
with Itemz([ItemID], [DVPath], [Level], [ParentID], [Ordinal], [PreviousID], [FromType], [ContentID], [DTS], [UserID],[pContentID],
|
||||||
|
[pDTS],[pUserID],PPath, [Path], [IsRNO], [POrdinalPath], [OrdinalPath]) as (
|
||||||
|
Select [I].[ItemID], '' DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID]
|
||||||
|
,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID],
|
||||||
|
Cast('' as nvarchar(max)) [PPath],
|
||||||
|
Cast(Case when C.Type < 20000 then @Delim + C.Number + @DelimNumber + C.Text else '1' end as nvarchar(max)) [Path],
|
||||||
|
0 IsRNO, Cast('' as nvarchar(max)) [POrdinalPath], Cast('0001' as nvarchar(max)) [OrdinalPath]
|
||||||
|
FROM [Items] I
|
||||||
|
Join Contents C on C.ContentID=I.ContentID
|
||||||
|
WHERE I.[ItemID] = @ProcID
|
||||||
|
Union All
|
||||||
|
-- Children
|
||||||
|
select I.[ItemID], DVPath, [Level] + 1,Z.ItemID,0, I.[PreviousID], P.[FromType],I.[ContentID],I.[DTS],I.[UserID],
|
||||||
|
P.[ContentID] [pContentID],P.[DTS] [pDTS],P.[UserID] [pUserID]
|
||||||
|
,PATH + --''
|
||||||
|
case C.Type/10000
|
||||||
|
when 2 then
|
||||||
|
case P.FromType
|
||||||
|
when 3 then @DelimStep + 'Caution'
|
||||||
|
when 4 then @DelimStep + 'Note'
|
||||||
|
else '' end
|
||||||
|
else '' end
|
||||||
|
PPath,
|
||||||
|
Path + case C.Type/10000
|
||||||
|
when 0 then @Delim +C.Number + @DelimNumber + C.Text
|
||||||
|
when 1 then @Delim +C.Number + @DelimNumber + C.Text
|
||||||
|
else
|
||||||
|
case P.FromType
|
||||||
|
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
|
||||||
|
--when 2 then 'SEC' + @Delim + cast(1 as varchar(3))
|
||||||
|
when 3 then @DelimStep +'Caution' + @DelimStep + cast(1 as varchar(3))
|
||||||
|
when 4 then @DelimStep +'Note' + @DelimStep + cast(1 as varchar(3))
|
||||||
|
when 5 then @DelimStep +'RNO' + @DelimStep
|
||||||
|
when 7 then @DelimStep +'Table' + @DelimStep
|
||||||
|
else case when Z.FromType < 3 then @Delim else @DelimStep end + cast(1 as varchar(3))
|
||||||
|
end end Path,
|
||||||
|
case when P.FromType = 5 then -1 else 0 end IsRNO,
|
||||||
|
OrdinalPath + '.' + Right('000' + Cast(P.FromType as varchar(4)), 4) + '-' ,
|
||||||
|
OrdinalPath + '.' + Right('000' + Cast(P.FromType as varchar(4)), 4) + '-00001'
|
||||||
|
from Itemz Z
|
||||||
|
join Parts P on P.ContentID = Z.ContentID
|
||||||
|
join Items I on I.ItemID = P.ItemID
|
||||||
|
join Contents C on C.ContentID = I.ContentID
|
||||||
|
Union All
|
||||||
|
-- Siblings
|
||||||
|
select I.[ItemID], DVPath, [Level] ,Z.[ParentID],Z.[Ordinal] +1, I.[PreviousID], [FromType],I.[ContentID],I.[DTS],I.[UserID]
|
||||||
|
,null,null,null,
|
||||||
|
PPath,
|
||||||
|
--'1' +
|
||||||
|
PPath + case C.Type/10000
|
||||||
|
when 0 then @Delim + C.Number + @DelimNumber + C.Text
|
||||||
|
when 1 then @Delim + C.Number + @DelimNumber + C.Text
|
||||||
|
else case when .dbo.vefn_GetLastDelim(Path) = '.' @DelimStep else @Delim end + cast(Ordinal + 2 as varchar(3))
|
||||||
|
end Path, 0,
|
||||||
|
POrdinalPath,
|
||||||
|
POrdinalPath + right('00000' + cast(Z.[Ordinal] + 2 as varchar(5)), 5)
|
||||||
|
from Itemz Z
|
||||||
|
join Items I on I.PreviousID = Z.ItemID
|
||||||
|
join Contents C on C.ContentID = I.ContentID
|
||||||
|
--where Z.[Level] > 0
|
||||||
|
|
||||||
|
)
|
||||||
|
insert into @SiblingAndChildren
|
||||||
|
select I.[ItemID], [DvPath], [Path], I.[Level],I.[FromType],I.[Ordinal], I.[ParentID], I.[PreviousID],I.[ContentID],I.[DTS],I.[UserID],
|
||||||
|
[pContentID],[pDTS],[pUserID],[IsRNO]/*,[PPath],[POrdinalPath]*/,[OrdinalPath]
|
||||||
|
from ItemZ I
|
||||||
|
OPTION (MAXRECURSION 10000)
|
||||||
|
END
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
-- Display the status of Proc creation
|
||||||
|
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsByProc Succeeded'
|
||||||
|
ELSE PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsByProc Error on Creation'
|
||||||
|
GO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user