Fixed search logic for empty search string. Improves performance.

Fixed logic to restore a deleted step.  If the first step is deleted and restored, the change manager fails.
Fixed numerous queries to give proper values if either the number or the number or the title is null.
Added testing examples to vefn_FixSearchString
This commit is contained in:
Rich 2012-10-31 15:54:52 +00:00
parent 2ae02cce49
commit bbcb9c6935

View File

@ -684,7 +684,9 @@ select 14 ID,'%' ss union
select 15 ID,'_' ss union select 15 ID,'_' ss union
select 16 ID,'-' ss union select 16 ID,'-' ss union
select 17 ID,'%' ss union select 17 ID,'%' ss union
select 18 ID,'C* - *' ss select 18 ID,'C* - *' ss union
select 19 ID,'' ss union
select 20 ID,null ss
) tt order by ID ) tt order by ID
*/ */
/***************************************************************************** /*****************************************************************************
@ -708,7 +710,8 @@ BEGIN
Set @SearchString = replace(@SearchString,'-','\u8209?') Set @SearchString = replace(@SearchString,'-','\u8209?')
IF(@SearchString like '[%]%') RETURN @SearchString IF(@SearchString like '[%]%') RETURN @SearchString
IF(@SearchString like '%[%]') RETURN @SearchString IF(@SearchString like '%[%]') RETURN @SearchString
RETURN '%' + @SearchString + '%' Set @SearchString = replace('%' + @SearchString + '%','%%','%')
RETURN @SearchString
END END
GO GO
-- Display the status -- Display the status
@ -748,27 +751,33 @@ CREATE PROCEDURE [dbo].[restoreDeletedItem]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
DECLARE @PreviousID int DECLARE @PreviousID int
declare @oldPreviousID int
DECLARE @NextID int DECLARE @NextID int
DECLARE @ContentID int DECLARE @ContentID int
declare @fromtype int declare @fromtype int
IF @Level = 0 IF @Level = 0 BEGIN
BEGIN
SET @NextID = @CurrentID SET @NextID = @CurrentID
SELECT @PreviousID = PreviousID FROM Items WHERE ItemID = @CurrentID SELECT @PreviousID = PreviousID FROM Items WHERE ItemID = @CurrentID
END END
IF @Level = 1 IF @Level = 1 BEGIN
BEGIN
SELECT @NextID = ItemID FROM Items WHERE PreviousID = @CurrentID SELECT @NextID = ItemID FROM Items WHERE PreviousID = @CurrentID
SET @PreviousID = @CurrentID SET @PreviousID = @CurrentID
END END
SELECT @ContentID = dbo.[ve_GetPartContentID](@ItemID) SELECT @ContentID = dbo.[ve_GetPartContentID](@ItemID)
select @fromtype = dbo.[ve_GetPartFromType](@ItemID) select @fromtype = dbo.[ve_GetPartFromType](@ItemID)
if @level = 2 select @oldPreviousID = isnull(PreviousID,0) from tblItems where ItemID = @ItemID
begin if @level = 2 begin
select @NextID = itemid from parts where contentid = @contentid and fromtype = @fromtype select @NextID = itemid from parts where contentid = @contentid and fromtype = @fromtype
end end
--restore parts from step being restored
UPDATE tblParts SET DeleteStatus = 0 WHERE ItemID IN (SELECT ItemID FROM PartAudits WHERE DeleteStatus = @DeleteID) UPDATE tblParts SET DeleteStatus = 0 WHERE ItemID IN (SELECT ItemID FROM PartAudits WHERE DeleteStatus = @DeleteID)
--print 'oldpreviousid: ' + cast(@oldpreviousid as varchar(10))
--print 'currentid: ' + cast(@currentid as varchar(10))
--restore of children in different order
if(@oldPreviousID != @CurrentID and @Level = 2) begin
update tblparts set deletestatus = 0, itemid = @itemid where contentid = @contentid and fromtype = @fromtype update tblparts set deletestatus = 0, itemid = @itemid where contentid = @contentid and fromtype = @fromtype
--print 'special code'
end
UPDATE tblContents SET DeleteStatus = 0, ActionDTS = getdate() WHERE ContentID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID) UPDATE tblContents SET DeleteStatus = 0, ActionDTS = getdate() WHERE ContentID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID)
UPDATE tblItems SET DeleteStatus = 0,PreviousID = CASE WHEN ItemID = @ItemID THEN @PreviousID ELSE PreviousID END UPDATE tblItems SET DeleteStatus = 0,PreviousID = CASE WHEN ItemID = @ItemID THEN @PreviousID ELSE PreviousID END
WHERE ItemID IN (SELECT ItemID FROM ItemAudits WHERE DeleteStatus = @DeleteID) WHERE ItemID IN (SELECT ItemID FROM ItemAudits WHERE DeleteStatus = @DeleteID)
@ -777,12 +786,11 @@ update tblparts set deletestatus = 0, itemid = @itemid where contentid = @conten
UPDATE tblAnnotations SET DeleteStatus = 0, ActionDTS = getdate() WHERE deletestatus = @deleteid -- ItemID in (SELECT ItemID FROM ItemAudits WHERE DeleteStatus = @DeleteID) UPDATE tblAnnotations SET DeleteStatus = 0, ActionDTS = getdate() WHERE deletestatus = @deleteid -- ItemID in (SELECT ItemID FROM ItemAudits WHERE DeleteStatus = @DeleteID)
UPDATE tblROUsages SET DeleteStatus = 0 WHERE deletestatus = @deleteid --ContentID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID) UPDATE tblROUsages SET DeleteStatus = 0 WHERE deletestatus = @deleteid --ContentID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID)
UPDATE tblTransitions SET DeleteStatus = 0 WHERE deletestatus = @deleteid --FromID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID) UPDATE tblTransitions SET DeleteStatus = 0 WHERE deletestatus = @deleteid --FromID IN (SELECT ContentID FROM ContentAudits WHERE DeleteStatus = @DeleteID)
IF @NextID IS NOT NULL IF @NextID IS NOT NULL BEGIN
BEGIN
UPDATE Items SET PreviousID = @ItemID WHERE ItemID = @NextID UPDATE Items SET PreviousID = @ItemID WHERE ItemID = @NextID
IF @ContentID IS NOT NULL IF @ContentID IS NOT NULL BEGIN
BEGIN
UPDATE Parts SET ItemID = @ItemID WHERE ItemID = @NextID and ContentID = @ContentID UPDATE Parts SET ItemID = @ItemID WHERE ItemID = @NextID and ContentID = @ContentID
--print 'old code'
END END
END END
--else --else
@ -928,8 +936,8 @@ BEGIN
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim +C.Number + @DelimNumber + C.Text when 0 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim +C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -962,8 +970,8 @@ BEGIN
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim +C.Number + @DelimNumber + C.Text when 0 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim +C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -989,8 +997,8 @@ BEGIN
PPath, PPath,
--'1' + --'1' +
PPath + case C.Type/10000 PPath + case C.Type/10000
when 0 then @Delim + C.Number + @DelimNumber + C.Text when 0 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end + else case when .dbo.vefn_GetLastDelim(Path) = '.' then @DelimStep else @Delim end +
case when I.deletestatus != 0 then 'Old ' else '' end + cast(Ordinal + 2 as varchar(3)) case when I.deletestatus != 0 then 'Old ' else '' end + cast(Ordinal + 2 as varchar(3))
end Path, end Path,
@ -1239,7 +1247,7 @@ with Itemz([ItemID], [DVPath], [Level], [ParentID], [Ordinal], [PreviousID], [Fr
Select [I].[ItemID], DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID],
Cast('' as nvarchar(max)) [PPath], 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], Cast(Case when C.Type < 20000 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) [Path],
0 IsRNO, Cast('' as nvarchar(max)) [POrdinalPath], Cast('0001' as nvarchar(max)) [OrdinalPath], UnitPrefix 0 IsRNO, Cast('' as nvarchar(max)) [POrdinalPath], Cast('0001' as nvarchar(max)) [OrdinalPath], UnitPrefix
FROM [Items] I FROM [Items] I
Join Contents C on C.ContentID=I.ContentID Join Contents C on C.ContentID=I.ContentID
@ -1259,8 +1267,8 @@ Union All
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text -- Procedure when 0 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') -- Procedure
when 1 then @Delim + C.Number + @DelimNumber + C.Text -- Section when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') -- Section
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -1285,8 +1293,8 @@ Union All
PPath, PPath,
--'1' + --'1' +
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 + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') -- Procedure
when 1 then @Delim + C.Number + @DelimNumber + C.Text -- Section when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') -- Section
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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,
@ -1389,7 +1397,7 @@ with Itemz(DVPath, [Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [From
Select DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [I].[ItemID], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID],[I].[LastChanged] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID], [I].[LastChanged] [pLastChanged],
Cast('' as nvarchar(max)) PPath, 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, Cast(Case when C.Type < 20000 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) Path,
0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix 0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix
FROM [Items] I FROM [Items] I
Join Contents C on C.ContentID=I.ContentID Join Contents C on C.ContentID=I.ContentID
@ -1409,8 +1417,8 @@ Union All
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text when 0 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -1435,8 +1443,8 @@ Union All
,PPath, ,PPath,
--'1' + --'1' +
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 + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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,
@ -1531,7 +1539,7 @@ with Itemz(DVPath, [Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [From
Select DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [I].[ItemID], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID],[I].[LastChanged] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID], [I].[LastChanged] [pLastChanged],
Cast('' as nvarchar(max)) PPath, 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, Cast(Case when C.Type < 20000 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) Path,
0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix 0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix
FROM [Items] I FROM [Items] I
Join Contents C on C.ContentID=I.ContentID Join Contents C on C.ContentID=I.ContentID
@ -1551,8 +1559,8 @@ Union All
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text when 0 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -1577,8 +1585,8 @@ Union All
,PPath, ,PPath,
--'1' + --'1' +
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 + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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,
@ -1773,7 +1781,7 @@ with Itemz(DVPath, [Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [From
Select DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [I].[ItemID], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID],[I].[LastChanged] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID], [I].[LastChanged] [pLastChanged],
Cast('' as nvarchar(max)) PPath, 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, Cast(Case when C.Type < 20000 then @Delim + @UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) Path,
0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, null 0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, null
FROM [Items] I FROM [Items] I
@ -1795,8 +1803,8 @@ Union All
PPath, PPath,
--Path + case when Z.FromType < 3 then @Delim else @DelimStep end + case C.Type/10000 --Path + case when Z.FromType < 3 then @Delim else @DelimStep end + case C.Type/10000
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text when 0 then @Delim + @UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text when 1 then @Delim + @UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -1822,8 +1830,8 @@ Union All
,PPath, ,PPath,
--'1' + --'1' +
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 + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + @UnitPrefix + C.Number + @DelimNumber + C.Text when 1 then @Delim + @UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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,
@ -1959,7 +1967,7 @@ with Itemz(DVPath, [Level], [ParentID], [Ordinal], [ItemID], [PreviousID], [From
Select DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [I].[ItemID], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID],[I].[LastChanged] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID], [I].[LastChanged] [pLastChanged],
Cast('' as nvarchar(max)) PPath, 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, Cast(Case when C.Type < 20000 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) Path,
0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix 0 IsRNO, Cast('' as nvarchar(max)) POrdinalPath, Cast('0001' as nvarchar(max)) OrdinalPath, UnitPrefix
FROM [Items] I FROM [Items] I
@ -1981,8 +1989,8 @@ Union All
PPath, PPath,
--Path + case when Z.FromType < 3 then @Delim else @DelimStep end + case C.Type/10000 --Path + case when Z.FromType < 3 then @Delim else @DelimStep end + case C.Type/10000
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim + UnitPrefix + C.Number + @DelimNumber + C.Text when 0 then @Delim + UnitPrefix + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -2007,8 +2015,8 @@ Union All
,PPath, ,PPath,
--'1' + --'1' +
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 + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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,
@ -2311,7 +2319,7 @@ with Itemz([ItemID], [DVPath], [Level], [ParentID], [Ordinal], [PreviousID], [Fr
Select [I].[ItemID], '' DVPath, 0 [Level], 0 [ParentID], 0 [Ordinal], [PreviousID],0 [FromType],[I].[ContentID],[I].[DTS],[I].[UserID] 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], ,0 [pContentID],[I].[DTS] [pDTS], [I].[UserID] [pUserID],
Cast('' as nvarchar(max)) [PPath], 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], Cast(Case when C.Type < 20000 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) [Path],
0 IsRNO, Cast('' as nvarchar(max)) [POrdinalPath], Cast('0001' as nvarchar(max)) [OrdinalPath] 0 IsRNO, Cast('' as nvarchar(max)) [POrdinalPath], Cast('0001' as nvarchar(max)) [OrdinalPath]
FROM [Items] I FROM [Items] I
Join Contents C on C.ContentID=I.ContentID Join Contents C on C.ContentID=I.ContentID
@ -2330,8 +2338,8 @@ Union All
else '' end else '' end
PPath, PPath,
Path + case C.Type/10000 Path + case C.Type/10000
when 0 then @Delim +C.Number + @DelimNumber + C.Text when 0 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim +C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else else
case P.FromType case P.FromType
--when 1 then 'PRC' + @Delim + cast(1 as varchar(3)) --when 1 then 'PRC' + @Delim + cast(1 as varchar(3))
@ -2356,9 +2364,9 @@ Union All
PPath, PPath,
--'1' + --'1' +
PPath + case C.Type/10000 PPath + case C.Type/10000
when 0 then @Delim + C.Number + @DelimNumber + C.Text when 0 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
when 1 then @Delim + C.Number + @DelimNumber + C.Text when 1 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'')
else case when .dbo.vefn_GetLastDelim(Path) = '.' 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) POrdinalPath + right('00000' + cast(Z.[Ordinal] + 2 as varchar(5)), 5)
@ -2382,6 +2390,7 @@ IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsByPr
ELSE PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsByProc Error on Creation' ELSE PRINT 'TableFunction Creation: vefn_SiblingAndChildrenItemsByProc Error on Creation'
GO GO
/****** Object: StoredProcedure [vefn_RemoveRange] ******/ /****** Object: StoredProcedure [vefn_RemoveRange] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_RemoveRange]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_RemoveRange]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_RemoveRange]; DROP FUNCTION [vefn_RemoveRange];
@ -2432,4 +2441,255 @@ GO
-- Display the status of Proc creation -- Display the status of Proc creation
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_RemoveRange Succeeded' IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_RemoveRange Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_RemoveRange Error on Creation' ELSE PRINT 'ScalarFunction Creation: vefn_RemoveRange Error on Creation'
GO GO
/****** Object: StoredProcedure [ve_GetPath] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetPath]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [ve_GetPath];
GO
/*
select ItemID, CC.Type, dbo.ve_GetPath(ItemID)
from Items II join Contents CC on II.ContentID = CC.ContentID
where ItemID in(111,265,266,267)
*/
-- drop function ve_GetPath
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[ve_GetPath] (@ItemID int) RETURNS varchar(max)
WITH EXECUTE AS OWNER
AS
BEGIN
-- declare @STructID int
--set @StructID=11
declare @Path varchar(max);
with Itemz(ItemCount,ItemID,PreviousID,FromType,CType,Number,Text,PPath, Path) as (
Select 1,ItemID,PreviousID,0,C.Type/10000,C.Number,C.Text,
Cast(Case when C.Type < 20000 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'') else '' end as nvarchar(max)) PPath,
Cast(Case when C.Type < 20000 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'') else '1' end as nvarchar(max)) Path
from Items I
join Contents C on I.ContentID = C.ContentID
where ItemID=@ItemID
Union All
-- siblings
Select ItemCount+1,I.PreviousID,II.PreviousID,0,C.Type/10000,Z.Number,Z.Text,PPath,cast(ItemCount + 1 as nvarchar(3)) + PPath
from Items I
join Contents C on I.ContentID = C.ContentID
Join Items II on II.ItemID = I.PreviousID
Join Itemz Z on I.ItemID=Z.ItemID
where I.PreviousID != 0
Union All
-- children
select 1,I.ItemID,I.PreviousID,P.FromType,C.Type/10000,C.Number,C.Text,
case C.Type/10000
when 0 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'')
when 1 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'') +'`' + cast(ItemCount + 0 as varchar(3))
else
case P.FromType
when 1 then 'PRC`' + cast(ItemCount + 0 as varchar(3))
when 2 then '`SEC`' + cast(ItemCount + 0 as varchar(3))
when 3 then '`Caution`' + cast(ItemCount + 0 as varchar(3))
when 4 then '`Note`' + cast(ItemCount + 0 as varchar(3))
when 5 then '`RNO`'
when 7 then '`Table`'
else '`' + cast(ItemCount + 0 as varchar(3))
end end + PPath PPath,
--'1' +
case C.Type/10000
when 0 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'')
when 1 then '`' + Isnull(C.Number,'') +'`' + Isnull(C.Text,'') +'`' + cast(ItemCount + 0 as varchar(3))
else
case P.FromType
when 1 then 'PRC`' + cast(ItemCount + 0 as varchar(3))
when 2 then '`SEC`' + cast(ItemCount + 0 as varchar(3))
when 3 then '`Caution`' + cast(ItemCount + 0 as varchar(3))
when 4 then '`Note`' + cast(ItemCount + 0 as varchar(3))
when 5 then '`RNO'
when 7 then '`Table'
else '`' + cast(ItemCount + 0 as varchar(3))
end end + PPath Path
from Parts P
join Items I on I.ContentID = P.ContentID
join Contents C on I.ContentID = C.ContentID
join Itemz Z on P.ItemID=Z.ItemID
)
select @Path = path From Itemz where ItemCount=1 and CType=0
OPTION (MAXRECURSION 10000)
return @Path
END;
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'ScalarFunction Creation: ve_GetPath Succeeded'
ELSE PRINT 'ScalarFunction Creation: ve_GetPath Error on Creation'
GO
/****** Object: StoredProcedure [vefn_ProcedureByProcID] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_ProcedureByProcID]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_ProcedureByProcID];
GO
/****** Object: UserDefinedFunction [dbo].[vefn_ProcedureByProcID] Script Date: 05/18/2011 11:20:48 ******/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
create FUNCTION [dbo].[vefn_ProcedureByProcID](@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
insert into @SiblingAndChildren
Select
[I].[ItemID]
, '' DVPath
, Cast(Case when C.Type < 20000 then @Delim + Isnull(C.Number,'') + @DelimNumber + Isnull(C.Text,'') else '1' end as nvarchar(max)) [Path]
,0 [Level]
,0 [FromType]
, 0 [Ordinal]
, 0 [ParentID]
, [PreviousID]
,[I].[ContentID]
,[I].[DTS]
,[I].[UserID]
,0 [pContentID]
,[I].[DTS] [pDTS]
, [I].[UserID] [pUserID]
,0 IsRNO
, Cast('0001' as nvarchar(max)) [OrdinalPath]
FROM [Items] I
Join Contents C on C.ContentID=I.ContentID
WHERE I.[ItemID] = @ProcID
END
RETURN
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_ProcedureByProcID Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_ProcedureByProcID Error on Creation'
GO
/****** Object: StoredProcedure [vefn_FindText] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FindText]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_FindText];
GO
/*
SELECT * From vefn_FindText('1','turbine-driven',0,0,0,1,'')
SELECT * From vefn_FindText('1','turbine\u8209?driven',0,0,0,0,'')
SELECT * From vefn_FindText('1','trip',0,0,0,0,'')
select * from vefn_FindText('1','',0,0,0,1,'20010,20008')
select * from vefn_FindText('1',null,0,0,0,1,'20010,20008')
select * from vefn_FindText('1',' ',0,0,0,1,'20010,20008')
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_FindText](
@DocVersionList nvarchar(MAX)
,@SearchString varchar(MAX)
,@CaseSensitive as int
,@IncludeLinks as int
,@IncludeRtfFormatting as int
,@IncludeSpecialCharacters as int
,@StepTypeList varchar(MAX))
RETURNS @FoundContents TABLE
(
ContentID int PRIMARY KEY
)
WITH EXECUTE AS OWNER
AS
BEGIN
Set @SearchString = .dbo.vefn_FixSearchString(@SearchString)
IF isnull(@SearchString,'%')='%'
BEGIN
insert into @FoundContents
select C.ContentID from (select * from Contents where ContentID in(select ContentID from vefn_DVContent(@DocVersionList))) C
where(isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
or (dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))
END
ELSE
BEGIN
Declare @SearchStringx nvarchar(200) --kbr
set @SearchStringx = replace(@SearchString,'-','\u8209?') --kbr
IF @CaseSensitive = 0 -- Not Case Sensitive
BEGIN
insert into @FoundContents
select C.ContentID from vefn_FindContentText(@DocVersionList,@SearchStringx) C
where
(.dbo.vefn_RemoveExtraText(C.Text,@IncludeLinks, @IncludeRtfFormatting, @IncludeSpecialCharacters) like @SearchStringx Collate SQL_Latin1_General_CP1_CI_AS)
AND ((isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
or ((dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))))
UNION
select C.ContentID from (select * from Contents where ContentID in(select ContentID from vefn_DVContent(@DocVersionList))) C
join Entries E on C.ContentID = E.ContentID
join Documents D on E.DocID = D.DocID
where
(D.DocAscii like @SearchString Collate SQL_Latin1_General_CP1_CI_AS)
AND
((isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
or ((dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))))
END
ELSE
BEGIN
IF @CaseSensitive = 1 -- Case Sensitive
BEGIN
insert into @FoundContents
select C.ContentID from vefn_FindContentText(@DocVersionList,@SearchStringx) C
where
(.dbo.vefn_RemoveExtraText(C.Text,@IncludeLinks, @IncludeRtfFormatting, @IncludeSpecialCharacters) like @SearchStringx Collate SQL_Latin1_General_CP1_CS_AS)
AND ((isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
or ((dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))))
UNION
select C.ContentID from (select * from Contents where ContentID in(select ContentID from vefn_DVContent(@DocVersionList))) C
join Entries E on C.ContentID = E.ContentID
join Documents D on E.DocID = D.DocID
where
(D.DocAscii like @SearchString Collate SQL_Latin1_General_CP1_CS_AS)
AND
((isnull(@StepTypeList,'') = '' and dbo.vefn_AllSections(C.Type)>=10000)
or ((dbo.vefn_AllSections(C.Type) in (Select ID from vefn_SplitInt(@StepTypeList,',')))))
END
END
END
RETURN
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_FindText Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_FindText Error on Creation'
GO