StmtText
--------------------------------------------------------------------------------------------------------------
declare @nId int--,
declare @nUserLang int
set @nId = 13067
set @nUserLang = 1
declare @uAgid uniqueidentifier
select @uAgid = AuditGlobalId from Audit where WebAuditId = @nId
(3 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1000]))
|--Index Seek(OBJECT:([DB].[dbo].[ Audit].[PK_WebAudit]), SEEK:([DB].[dbo].[ Audit].[WebAuditID]=[@nId]) ORDERED FORWARD)
|--RID Lookup(OBJECT:([DB].[dbo].[ Audit]), SEEK:([Bmk1000]=[Bmk1000]) LOOKUP ORDERED FORWARD)
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE #GetCats( nOrder int NOT NULL,
AuditGlobalId uniqueIdentifier NOT NULL,
CategoryGlobalId uniqueIdentifier NOT NULL,
ParentId uniqueIdentifier NULL,
CategoryIdentity int NOT NULL,
CategoryUniqueID
DECLARE @SubCats TABLE ( nOrder int NOT NULL,
AuditGlobalId uniqueIdentifier NOT NULL,
CategoryGlobalId uniqueIdentifier NOT NULL,
ParentId uniqueIdentifier NULL,
CategoryIdentity int NOT NULL,
CategorySequence int
(2 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:([tempdb].[dbo].[#GetCats]), SET:([tempdb].[dbo].[#GetCats].[nOrder] = RaiseIfNull([ParameterTable].[nOrder]),[tempdb].[dbo].[#GetCats].[AuditGlobalId] = RaiseIfNull([ParameterTable].[AuditGlobalId]),[tempdb].[dbo].[#GetCats].[Cate
|--Top(ROWCOUNT est 0)
|--Parameter Table Scan
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE ImpGetCategories
@uAgid uniqueidentifier,
@nUserLang int = 1,
@uCgid uniqueidentifier = NULL,
@nLevel int = 1,
@nIdsOnly int = 0
AS
--------------------------------------------------------------------------
CREATE PROCEDURE SQSGetConfigItem
@nUserLang int,
@strItemKey nvarchar(100),
@strItemValue nvarchar(4000) Output
AS
select @strItemValue = isnull(ItemValue, StandardValue) from SQSConfig where LanguageKey = @nUserLang and ItemKey = @st
(2 row(s) affected)
StmtText
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=isnull([DB].[dbo].[SQSConfig].[ItemValue],[DB].[dbo].[SQSConfig].[StandardValue])))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[SQSConfig].[PK_SQSConfig]), SEEK:([DB].[dbo].[SQSConfig].[LanguageKey]=[@nUserLang] AND [DB].[dbo].[SQSConfig].[ItemKey]=[@strItemKey]) ORDERED FORWARD)
(2 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
exec SQSGetConfigItem @nUserLang, 'labelSingleQuestion', @strSingle output
CREATE PROCEDURE SQSGetConfigItem
@nUserLang int,
@strItemKey nvarchar(100),
@strItemValue nvarchar(4000) Output
AS
select @strItemValue = isnull(ItemValue, StandardValue) from SQSConfig where LanguageKey = @nUserLang and ItemKey = @st
(2 row(s) affected)
StmtText
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=isnull([DB].[dbo].[SQSConfig].[ItemValue],[DB].[dbo].[SQSConfig].[StandardValue])))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[SQSConfig].[PK_SQSConfig]), SEEK:([DB].[dbo].[SQSConfig].[LanguageKey]=[@nUserLang] AND [DB].[dbo].[SQSConfig].[ItemKey]=[@strItemKey]) ORDERED FORWARD)
(2 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set @bCatWeightsOK = 1
create table #ImpCats ( Catcgid uniqueidentifier, l1 int NULL, l2 int NULL, l3 int NULL, l4 int NULL, l5 int NULL, l6 int NULL, l7 int NULL, l8 int NULL,
l9 int NULL, l10 int NULL, l11 int NULL, l12 int NULL, l13 int NULL, l14 int NULL, l15 in
create table #Out ( nOrder int identity, Outcgid uniqueidentifier, nLevel int, nSubCats int NULL, nQuestions int NULL)
---------------------------------------------------------------------------------------------------------------------------------
insert into #ImpCats (Catcgid, l1, nLevel)
select CategoryGlobalId, CategorySequence, 1
from Category
where AuditGlobalId = @uAgid
and (((@uCgid is NULL) and (ParentId is NULL)) or ((@uCgid is NOT NULL) and (ParentId = @uCgid)))
and Archi
(4 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:([tempdb].[dbo].[#ImpCats]), SET:([#ImpCats].[Catcgid] = [DB].[dbo].[Category].[CategoryGlobalID],[#ImpCats].[l1] = [DB].[dbo].[Category].[CategorySequence],[#ImpCats].[nLevel] = [Expr1007],[#ImpCats].[l2] = NULL,[#ImpCa
|--Compute Scalar(DEFINE:([Expr1007]=(1)))
|--Top(ROWCOUNT est 0)
|--Sort(ORDER BY:([DB].[dbo].[Category].[CategorySequence] ASC))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category]), SEEK:([DB].[dbo].[Category].[AuditGlobalID]=[@uAgid]), WHERE:([DB].[dbo].[Category].[Archived]=(0) AND [DB].[dbo].[Category].[Deleted]=(0) AND ([@
(5 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Set @n = 2
While (@n <= 15)
Begin
insert into #ImpCats
select c.CategoryGlobalId,
Parent.l1,
Case When @n = 2 Then c.CategorySequence Else Parent.l2 End,
Case When @n = 3 Then c.CategorySequence Else Parent.l3 End,
Case When @n = 4 Then c.CategorySequence Else P
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:([tempdb].[dbo].[#ImpCats]), SET:([#ImpCats].[Catcgid] = [DB].[dbo].[Category].[CategoryGlobalID] as [c].[CategoryGlobalID],[#ImpCats].[l1] = #ImpCats.[l1] as [Parent].[l1],[#ImpCats].[l2] = [Expr1009],[#ImpCats].[l3]
|--Table Spool
|--Compute Scalar(DEFINE:([Expr1009]=CASE WHEN [@n] = (2) THEN [DB].[dbo].[Category].[CategorySequence] as [c].[CategorySequence] ELSE #ImpCats.[l2] as [Parent].[l2] END, [Expr1010]=CASE WHEN [@n] = (3) THEN [DB].[dbo].[Category
|--Top(ROWCOUNT est 0)
|--Hash Match(Inner Join, HASH:([Parent].[Catcgid])=([c].[ParentID]), RESIDUAL:([DB].[dbo].[Category].[ParentID] as [c].[ParentID]=#ImpCats.[Catcgid] as [Parent].[Catcgid]))
|--Filter(WHERE:(CASE WHEN [@n] = (2) THEN #ImpCats.[l1] as [Parent].[l1] ELSE CASE WHEN [@n] = (3) THEN #ImpCats.[l2] as [Parent].[l2] ELSE CASE WHEN [@n] = (4) THEN #ImpCats.[l3] as [Parent].[l3] ELSE CASE WHEN [@n] =
| |--Table Scan(OBJECT:([tempdb].[dbo].[#ImpCats] AS [Parent]))
|--Clustered Index Scan(OBJECT:([DB].[dbo].[Category].[PK_Category] AS [c]), WHERE:([DB].[dbo].[Category].[Archived] as [c].[Archived]=(0) AND [DB].[dbo].[Category].[Deleted] as [c].[Deleted]=(0)))
(8 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Set @n = @n + 1
End
-- Compile
insert into #Out (Outcgid, nLevel, nSubCats, nQuestions)
select Catcgid, nLevel, nSubCats, Sum(Case When q.QuestionGlobalId is NULL Then 0 Else 1 End) as nQuestions
from (
select Catcgid, nLevel, Sum(Case When c.CategoryGlobalId
(2 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:([tempdb].[dbo].[#Out]), SET:([#Out].[Outcgid] = [#ImpCats].[Catcgid],[#Out].[nLevel] = [#ImpCats].[nLevel],[#Out].[nSubCats] = [Expr1010],[#Out].[nQuestions] = [Expr1014],[#Out].[nOrder] = [Expr1015]))
|--Compute Scalar(DEFINE:([Expr1015]=getidentity((24982910),(2),N'#Out')))
|--Top(ROWCOUNT est 0)
|--Stream Aggregate(GROUP BY:([#ImpCats].[l1], [#ImpCats].[l2], [#ImpCats].[l3], [#ImpCats].[l4], [#ImpCats].[l5], [#ImpCats].[l6], [#ImpCats].[l7], [#ImpCats].[l8], [#ImpCats].[l9], [#ImpCats].[l10], [#ImpCats].[l11], [#ImpCats].[l12
|--Compute Scalar(DEFINE:([Expr1016]=CASE WHEN [DB].[dbo].[Question].[QuestionGlobalID] as [q].[QuestionGlobalID] IS NULL THEN (0) ELSE (1) END))
|--Nested Loops(Left Outer Join, OUTER REFERENCES:([#ImpCats].[Catcgid]))
|--Stream Aggregate(GROUP BY:([#ImpCats].[l1], [#ImpCats].[l2], [#ImpCats].[l3], [#ImpCats].[l4], [#ImpCats].[l5], [#ImpCats].[l6], [#ImpCats].[l7], [#ImpCats].[l8], [#ImpCats].[l9], [#ImpCats].[l10], [#ImpCats].[l11],
| |--Compute Scalar(DEFINE:([Expr1017]=CASE WHEN [DB].[dbo].[Category].[CategoryGlobalID] as [c].[CategoryGlobalID] IS NULL THEN (0) ELSE (1) END))
| |--Nested Loops(Left Outer Join, WHERE:([DB].[dbo].[Category].[ParentID] as [c].[ParentID]=[#ImpCats].[Catcgid]))
| |--Sort(ORDER BY:([#ImpCats].[l1] ASC, [#ImpCats].[l2] ASC, [#ImpCats].[l3] ASC, [#ImpCats].[l4] ASC, [#ImpCats].[l5] ASC, [#ImpCats].[l6] ASC, [#ImpCats].[l7] ASC, [#ImpCats].[l8] ASC, [#ImpCats].[l9] AS
| | |--Table Scan(OBJECT:([tempdb].[dbo].[#ImpCats]))
| |--Clustered Index Scan(OBJECT:([DB].[dbo].[Category].[PK_Category] AS [c]), WHERE:([DB].[dbo].[Category].[Archived] as [c].[Archived]=(0) AND [DB].[dbo].[Category].[Deleted] as [c].[Deleted]=(0)
|--Filter(WHERE:([DB].[dbo].[Question].[Archived] as [q].[Archived]=(0) AND [DB].[dbo].[Question].[Deleted] as [q].[Deleted]=(0)))
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1011]))
|--Index Seek(OBJECT:([DB].[dbo].[Question].[IX_Question_QuestionSequence] AS [q]), SEEK:([q].[CategoryGlobalID]=[#ImpCats].[Catcgid]) ORDERED FORWARD)
|--RID Lookup(OBJECT:([DB].[dbo].[Question] AS [q]), SEEK:([Bmk1011]=[Bmk1011]) LOOKUP ORDERED FORWARD)
(16 row(s) affected)
StmtText
---------------------------------------------------------------------------------------
if exists (select * from SQSOption where OptionId = 'weightedcats' and Setting = 1)
(1 row(s) affected)
StmtText
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1005]=CASE WHEN [Expr1006] THEN (1) ELSE (0) END))
|--Nested Loops(Left Semi Join, DEFINE:([Expr1006] = [PROBE VALUE]))
|--Constant Scan
|--Filter(WHERE:([DB].[dbo].[SQSOption].[Setting]=(1)))
|--Nested Loops(Inner Join, OUTER REFERENCES:([Uniq1002], [DB].[dbo].[SQSOption].[ClientID]))
|--Index Seek(OBJECT:([DB].[dbo].[SQSOption].[PK_SQSOption]), SEEK:([DB].[dbo].[SQSOption].[OptionID]=N'weightedcats') ORDERED FORWARD)
|--Clustered Index Seek(OBJECT:([DB].[dbo].[SQSOption].[IX_SQSOption_ClientId]), SEEK:([DB].[dbo].[SQSOption].[ClientID]=[DB].[dbo].[SQSOption].[ClientID] AND [Uniq1002]=[Uniq1002]) LOOKUP ORDERED FORWARD)
(7 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin
-- Determine if every top level category has a weight and the sum is 100
select @nTotCnt = count(*) from Category where AuditGlobalId = @uAgid and ParentId is NULL and Archived = 0 and Deleted = 0
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=CONVERT_IMPLICIT(int,[Expr1004],0)))
|--Stream Aggregate(DEFINE:([Expr1004]=Count(*)))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category]), SEEK:([DB].[dbo].[Category].[AuditGlobalID]=[@uAgid]), WHERE:([DB].[dbo].[Category].[ParentID] IS NULL AND [DB].[dbo].[Category].[Archived]=(0) AND [Ty
(3 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
select @nWeightCnt = count(*) from Category where AuditGlobalId = @uAgid and ParentId is NULL and Archived = 0 and Deleted = 0 and CategoryWeight is NOT NULL
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=CONVERT_IMPLICIT(int,[Expr1004],0)))
|--Stream Aggregate(DEFINE:([Expr1004]=Count(*)))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category]), SEEK:([DB].[dbo].[Category].[AuditGlobalID]=[@uAgid]), WHERE:([DB].[dbo].[Category].[ParentID] IS NULL AND [DB].[dbo].[Category].[Archived]=(0) AND [Ty
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
select @nSum = sum(CategoryWeight) from Category where AuditGlobalId = @uAgid and ParentId is NULL and Archived = 0 and Deleted = 0 and CategoryWeight is NOT NULL
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=CASE WHEN [Expr1004]=(0) THEN NULL ELSE [Expr1005] END))
|--Stream Aggregate(DEFINE:([Expr1004]=Count(*), [Expr1005]=SUM([DB].[dbo].[Category].[CategoryWeight])))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category]), SEEK:([DB].[dbo].[Category].[AuditGlobalID]=[@uAgid]), WHERE:([DB].[dbo].[Category].[ParentID] IS NULL AND [DB].[dbo].[Category].[Archived]=(0) AND [Ty
(3 row(s) affected)
StmtText
-----------------------------------------------------------------------------------------------------------------------------------------
select @nSubCnt = count(*) from Category where AuditGlobalId = @uAgid and ParentId is NOT NULL and Archived = 0 and Deleted = 0
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1003]=CONVERT_IMPLICIT(int,[Expr1004],0)))
|--Stream Aggregate(DEFINE:([Expr1004]=Count(*)))
|--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category]), SEEK:([DB].[dbo].[Category].[AuditGlobalID]=[@uAgid]), WHERE:([DB].[dbo].[Category].[Archived]=(0) AND [DB].[dbo].[Category].[Deleted]=(0) AND [DB].
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if((@nWeightCnt > 0) and (((@nTotCnt - @nWeightCnt) > 0) or (@nSum <> 100) or (@nSubCnt > 0)))
set @bCatWeightsOK = 0
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- RETURN
select #Out.nOrder, c.*, #Out.nLevel, CategoryViewLabel = Case When c.CategoryView = 1 Then @strCatList Else @strSingle End,
nSubCats, nQuestions, cl.CategoryName, @bCatWeightsOK as CatWeightsOK, cdd.categoryduedates
from Category c
join Cat
(4 row(s) affected)
StmtText
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1010]=CASE WHEN [DB].[dbo].[Category].[CategoryView] as [c].[CategoryView]=(1) THEN [@strCatList] ELSE [@strSingle] END))
|--Nested Loops(Left Outer Join, OUTER REFERENCES:([c].[CategoryGlobalID]))
|--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
| |--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
| | |--Sort(ORDER BY:([#Out].[nOrder] ASC))
| | | |--Table Scan(OBJECT:([tempdb].[dbo].[#Out]))
| | |--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category] AS [c]), SEEK:([c].[AuditGlobalID]=[@uAgid] AND [c].[CategoryGlobalID]=[#Out].[Outcgid]) ORDERED FORWARD)
| |--Clustered Index Seek(OBJECT:([DB].[dbo].[CategoryLanguage].[PK_CategoryLanguage] AS [cl]), SEEK:([cl].[CategoryGlobalID]=[#Out].[Outcgid] AND [cl].[LanguageKey]=[@nUserLang]) ORDERED FORWARD)
|--Clustered Index Seek(OBJECT:([DB].[dbo].[CategoryDueDates].[PK_CategoryDueDates] AS [cdd]), SEEK:([cdd].[CategoryGlobalID]=[DB].[dbo].[Category].[CategoryGlobalID] as [c].[CategoryGlobalID]) ORDERED FORWARD)
(9 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Else If (@nIdsOnly = 2)
select #Out.nOrder, c.CategoryGlobalId, c.ParentId, c.CategoryReference, #OUT.nLevel, c.Archived, c.Deleted
from Category c, CategoryLanguage cl, #Out
where c.AuditGlobalId = @uAgid
and c.CategoryGlobalId = #Out.Outcgid
and c.CategoryGloba
(2 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
|--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
| |--Sort(ORDER BY:([#Out].[nOrder] ASC))
| | |--Table Scan(OBJECT:([tempdb].[dbo].[#Out]))
| |--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category] AS [c]), SEEK:([c].[AuditGlobalID]=[@uAgid] AND [c].[CategoryGlobalID]=[#Out].[Outcgid]) ORDERED FORWARD)
|--Clustered Index Seek(OBJECT:([DB].[dbo].[CategoryLanguage].[PK_CategoryLanguage] AS [cl]), SEEK:([cl].[CategoryGlobalID]=[#Out].[Outcgid] AND [cl].[LanguageKey]=[@nUserLang]) ORDERED FORWARD)
(6 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Else
select #Out.nOrder, c.CategoryGlobalId
from Category c, CategoryLanguage cl, #Out
where c.AuditGlobalId = @uAgid
and c.CategoryGlobalId = #Out.Outcgid
and c.CategoryGlobalId = cl.CategoryGlobalId
and cl.LanguageKey = @nUserLang
(1 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Sort(ORDER BY:([#Out].[nOrder] ASC))
|--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
|--Nested Loops(Inner Join, OUTER REFERENCES:([#Out].[Outcgid]))
| |--Table Scan(OBJECT:([tempdb].[dbo].[#Out]))
| |--Clustered Index Seek(OBJECT:([DB].[dbo].[Category].[PK_Category] AS [c]), SEEK:([c].[AuditGlobalID]=[@uAgid] AND [c].[CategoryGlobalID]=[#Out].[Outcgid]) ORDERED FORWARD)
|--Clustered Index Seek(OBJECT:([DB].[dbo].[CategoryLanguage].[PK_CategoryLanguage] AS [cl]), SEEK:([cl].[CategoryGlobalID]=[#Out].[Outcgid] AND [cl].[LanguageKey]=[@nUserLang]) ORDERED FORWARD)
(6 row(s) affected)
StmtText
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
drop table #Out
drop table #ImpCats
insert @SubCats
select nOrder, AuditGlobalId, CategoryGlobalId, ParentId, CategoryIdentity, CategorySequence, CategoryName,
CategoryView, NULL, CategoryAnswer, ReAuditCategory, nLevel, nSubCats, nQuestions, 0, 0
from #GetCats
(3 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:(@SubCats), SET:([nOrder] = [tempdb].[dbo].[#GetCats].[nOrder],[AuditGlobalId] = [tempdb].[dbo].[#GetCats].[AuditGlobalId],[CategoryGlobalId] = [tempdb].[dbo].[#GetCats].[CategoryGlobalId],[ParentId] = [tempdb].[dbo].[#GetCats].[Pa
|--Compute Scalar(DEFINE:([Expr1008]=NULL, [Expr1009]=(0), [Expr1010]=(0)))
|--Top(ROWCOUNT est 0)
|--Table Scan(OBJECT:([tempdb].[dbo].[#GetCats]))
(4 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
insert into @IQ
select q.QuestionIdentity,
0, -- DynamicInclude
qrh.DynamicInclude,-- QuestionREsultn
CASE when cql.QuestionGlobalID IS NULL then 0 ELSE 1 end as triggered,
CASE when Activated.QActivated IS NULL then 0 When Activated.QActivate
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Insert(OBJECT:(@IQ), SET:([QuestionIdentity] = [DB].[dbo].[Question].[QuestionIdentity] as [q].[QuestionIdentity],[DynamicInclude] = [Expr1040],[QuestionResult] = [Expr1041],[Triggered] = [Expr1042],[activated] = [Expr1043],[AuditGlobalID] =
|--Compute Scalar(DEFINE:([Expr1040]=(0), [Expr1043]=CONVERT_IMPLICIT(bit,CASE WHEN [Expr1035] IS NULL THEN (0) ELSE CASE WHEN [Expr1035]=(0) THEN (0) ELSE (1) END END,0)))
|--Top(ROWCOUNT est 0)
|--Compute Scalar(DEFINE:([Expr1042]=CONVERT_IMPLICIT(bit,CASE WHEN [DB].[dbo].[ChoiceQuestionList].[QuestionGlobalID] as [cql].[QuestionGlobalID] IS NULL THEN (0) ELSE (1) END,0)))
|--Hash Match(Left Outer Join, HASH:([q].[QuestionGlobalID])=([cql].[QuestionGlobalID]), RESIDUAL:([DB].[dbo].[ChoiceQuestionList].[QuestionGlobalID] as [cql].[QuestionGlobalID]=[DB].[dbo].[Question].[QuestionGlobalID] as [q].[Q
|--Hash Match(Left Outer Join, HASH:([q].[QuestionGlobalID])=([aq].[QuestionGlobalID]), RESIDUAL:([DB].[dbo].[Question].[QuestionGlobalID] as [aq].[QuestionGlobalID]=[DB].[dbo].[Question].[QuestionGlobalID] as [q].[Question
| |--Compute Scalar(DEFINE:([Expr1041]=CONVERT_IMPLICIT(int,[DB].[dbo].[ QuestionResultHistory].[DynamicInclude] as [qrh].[DynamicInclude],0)))
| | |--Hash Match(Right Outer Join, HASH:([qrh].[QuestionIdentity])=([q].[QuestionIdentity]))
| | |--Top(TOP EXPRESSION:((1)))
| | | |--Segment
| | | |--Clustered Index Seek(OBJECT:([DB].[dbo].[ QuestionResultHistory].[PK_ QuestionResultHistory] AS [qrh]), SEEK:([qrh].[WebAuditID]=[@nId]) ORDERED BACKWARD)
| | |--Hash Match(Inner Join, HASH:([q].[CategoryGlobalID])=([c].[CategoryGlobalID]), RESIDUAL:([DB].[dbo].[Category].[CategoryGlobalID] as [c].[CategoryGlobalID]=[DB].[dbo].[Question].[CategoryGlobalID] as [q].[
| | |--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1004], [Expr1058]) WITH UNORDERED PREFETCH)
| | | |--Nested Loops(Inner Join, OUTER REFERENCES:([ma].[AuditGlobalID]))
| | | | |--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1007]))
| | | | | |--Index Seek(OBJECT:([DB].[dbo].[ Audit].[PK_WebAudit] AS [ma]), SEEK:([ma].[WebAuditID]=[@nId]) ORDERED FORWARD)
| | | | | |--RID Lookup(OBJECT:([DB].[dbo].[ Audit] AS [ma]), SEEK:([Bmk1007]=[Bmk1007]) LOOKUP ORDERED FORWARD)
| | | | |--Index Seek(OBJECT:([DB].[dbo].[Question].[PK_Question] AS [q]), SEEK:([q].[AuditGlobalID]=[DB].[dbo].[ Audit].[AuditGlobalID] as [ma].[AuditGlobalID]) ORDERED FORWARD)
| | | |--RID Lookup(OBJECT:([DB].[dbo].[Question] AS [q]), SEEK:([Bmk1004]=[Bmk1004]) LOOKUP ORDERED FORWARD)
| | |--Index Scan(OBJECT:([DB].[dbo].[Category].[IX_CategoryGlobalId] AS [c]))
| |--Compute Scalar(DEFINE:([Expr1035]=[Expr1035]))
| |--Compute Scalar(DEFINE:([Expr1035]=CONVERT_IMPLICIT(int,[Expr1063],0)))
| |--Stream Aggregate(GROUP BY:([aq].[QuestionGlobalID]) DEFINE:([Expr1063]=Count(*)))
| |--Sort(ORDER BY:([aq].[QuestionGlobalID] ASC))
| |--Hash Match(Inner Join, HASH:([cql].[QuestionGlobalID])=([aq].[QuestionGlobalID]), RESIDUAL:([DB].[dbo].[Question].[QuestionGlobalID] as [aq].[QuestionGlobalID]=[DB].[dbo].[ChoiceQuestionList].[Qu
| |--Hash Match(Inner Join, HASH:([tc].[ChoiceGlobalID])=([cql].[ChoiceGlobalID]), RESIDUAL:([DB].[dbo].[ChoiceQuestionList].[ChoiceGlobalID] as [cql].[ChoiceGlobalID]=[DB].[dbo].[Choice].[Choice
| | |--Filter(WHERE:([DB].[dbo].[Question].[QuestionIdentity] as [tq].[QuestionIdentity]=[DB].[dbo].[ QuestionResultHistory].[QuestionIdentity]))
| | | |--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1026], [Expr1062]) WITH UNORDERED PREFETCH)
| | | |--Nested Loops(Inner Join, OUTER REFERENCES:([tc].[QuestionGlobalID], [Expr1061]) WITH UNORDERED PREFETCH)
| | | | |--Nested Loops(Inner Join, OUTER REFERENCES:([tc].[AuditGlobalID], [tc].[ChoiceGlobalID], [Expr1060]) WITH UNORDERED PREFETCH)
| | | | | |--Nested Loops(Inner Join, OUTER REFERENCES:([tqrh].[ChoiceIdentity], [Expr1059]) WITH UNORDERED PREFETCH)
| | | | | | |--Hash Match(Inner Join, HASH:([DB].[dbo].[ QuestionResultHistory].[QuestionIdentity], [Expr1034])=([tqrh].[QuestionIdentity], [tqrh].[TimeStamp]), RESIDUAL:([Tys
| | | | | | | |--Stream Aggregate(GROUP BY:([DB].[dbo].[ QuestionResultHistory].[QuestionIdentity]) DEFINE:([Expr1034]=MAX([DB].[dbo].[ QuestionResultHistory].[TimeSt
| | | | | | | | |--Clustered Index Seek(OBJECT:([DB].[dbo].[ QuestionResultHistory].[PK_ QuestionResultHistory]), SEEK:([DB].[dbo].[ QuestionResultHistory].[Web
| | | | | | | |--Clustered Index Seek(OBJECT:([DB].[dbo].[ QuestionResultHistory].[PK_ QuestionResultHistory] AS [tqrh]), SEEK:([tqrh].[WebAuditID]=[@nId]), WHERE:([Tys
| | | | | | |--Index Seek(OBJECT:([DB].[dbo].[Choice].[IX_Choice] AS [tc]), SEEK:([tc].[ChoiceIdentity]=[DB].[dbo].[ QuestionResultHistory].[ChoiceIdentity] as [tqrh].[Choi
| | | | | |--Clustered Index Seek(OBJECT:([DB].[dbo].[Choice].[PK_Choice] AS [tc]), SEEK:([tc].[AuditGlobalID]=[DB].[dbo].[Choice].[AuditGlobalID] as [tc].[AuditGlobalID] AND [tc
| | | | |--Index Seek(OBJECT:([DB].[dbo].[Question].[IX_QuestionGlobalId] AS [tq]), SEEK:([tq].[QuestionGlobalID]=[DB].[dbo].[Choice].[QuestionGlobalID] as [tc].[QuestionGlobalID])
| | | |--RID Lookup(OBJECT:([DB].[dbo].[Question] AS [tq]), SEEK:([Bmk1026]=[Bmk1026]) LOOKUP ORDERED FORWARD)
| | |--Clustered Index Scan(OBJECT:([DB].[dbo].[ChoiceQuestionList].[PK_ChoiceQuestionList] AS [cql]))
| |--Index Scan(OBJECT:([DB].[dbo].[Question].[IX_QuestionGlobalId] AS [aq]))
|--Clustered Index Scan(OBJECT:([DB].[dbo].[ChoiceQuestionList].[PK_ChoiceQuestionList] AS [cql]))
(42 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------
update @IQ
set dynamicinclude = 1
where (questionresult = 1 and triggered = 0)
or (triggered = 0)
or (triggered = 1 and activated = 1)
(1 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------
|--Table Update(OBJECT:(@IQ), SET:([DynamicInclude] = [Expr1004]))
|--Compute Scalar(DEFINE:([Expr1004]=(1)))
|--Top(ROWCOUNT est 0)
|--Table Scan(OBJECT:(@IQ), WHERE:([Triggered]=(0) OR [Triggered]=(1) AND [activated]=(1)) ORDERED)
(4 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
update sc
set nCatCompleted = 1
from @SubCats SC
left join
(
select q.CategoryGlobalID, count(*) as catCount
from Question q
join @iq iq
on q.AuditGlobalID = iq.AuditGlobalID
and q.CategoryGlobalid = iq.CategoryGlobalID
and q.
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Update(OBJECT:(@SubCats), SET:([nCatCompleted] = [Expr1032]))
|--Compute Scalar(DEFINE:([Expr1032]=(1)))
|--Top(ROWCOUNT est 0)
|--Filter(WHERE:(isnull([Expr1009],(0))=isnull([Expr1029],(0))))
|--Nested Loops(Left Outer Join, OUTER REFERENCES:([q].[CategoryGlobalID]))
|--Nested Loops(Left Outer Join, OUTER REFERENCES:([SC].[CategoryGlobalId]))
| |--Table Scan(OBJECT:(@SubCats AS [SC]))
| |--Compute Scalar(DEFINE:([q].[CategoryGlobalID]=[DB].[dbo].[Question].[CategoryGlobalID] as [q].[CategoryGlobalID], [Expr1009]=[Expr1009]))
| |--Compute Scalar(DEFINE:([Expr1009]=CONVERT_IMPLICIT(int,[Expr1050],0)))
| |--Stream Aggregate(DEFINE:([Expr1050]=Count(*), [q].[CategoryGlobalID]=ANY([DB].[dbo].[Question].[CategoryGlobalID] as [q].[CategoryGlobalID])))
| |--Filter(WHERE:([DB].[dbo].[Question].[AuditGlobalID] as [q].[AuditGlobalID]=@iq.[AuditGlobalID] as [iq].[AuditGlobalID] AND [DB].[dbo].[Question].[CategoryGlobalID] as [q].[CategoryGlobalID]=@SubCats.[
| |--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1003]))
| |--Nested Loops(Inner Join, OUTER REFERENCES:([iq].[QuestionIdentity]))
| | |--Table Scan(OBJECT:(@iq AS [iq]), WHERE:(@iq.[CategoryGlobalID] as [iq].[CategoryGlobalID]=@SubCats.[CategoryGlobalId] as [SC].[CategoryGlobalId] AND @iq.[DynamicInclude] as [iq].[DynamicInclu
| | |--Index Seek(OBJECT:([DB].[dbo].[Question].[IX_Question_QuestionIdentity] AS [q]), SEEK:([q].[QuestionIdentity]=@iq.[QuestionIdentity] as [iq].[QuestionIdentity]) ORDERED FORWARD)
| |--RID Lookup(OBJECT:([DB].[dbo].[Question] AS [q]), SEEK:([Bmk1003]=[Bmk1003]) LOOKUP ORDERED FORWARD)
|--Compute Scalar(DEFINE:([Expr1029]=[Expr1029]))
|--Compute Scalar(DEFINE:([Expr1029]=CONVERT_IMPLICIT(int,[Expr1051],0)))
|--Stream Aggregate(DEFINE:([Expr1051]=Count(*)))
|--Filter(WHERE:([DB].[dbo].[ QuestionResultHistory].[TimeStamp] as [mqrh].[TimeStamp]=[Expr1027]))
|--Stream Aggregate(GROUP BY:([Bmk1016], [mqrh].[TimeStamp]) DEFINE:([Expr1027]=MAX([DB].[dbo].[ QuestionResultHistory].[TimeStamp])))
|--Nested Loops(Inner Join, OUTER REFERENCES:([iq].[QuestionIdentity]))
|--Nested Loops(Inner Join, OUTER REFERENCES:([iq].[QuestionIdentity]))
| |--Sort(ORDER BY:([Bmk1016] ASC))
| | |--Filter(WHERE:([Expr1038]=(1)))
| | |--Nested Loops(Inner Join, OUTER REFERENCES:([mqr].[QuestionIdentity]))
| | |--Nested Loops(Inner Join, OUTER REFERENCES:([iq].[QuestionIdentity]))
| | | |--Table Scan(OBJECT:(@IQ AS [iq]), WHERE:([DB].[dbo].[Question].[CategoryGlobalID] as [q].[CategoryGlobalID]=@IQ.[CategoryGlobalID] as [iq].[CategoryGlobalID] AND @IQ.[Dy
| | | |--Clustered Index Seek(OBJECT:([DB].[dbo].[ QuestionResult].[PK_ QuestionResult] AS [mqr]), SEEK:([mqr].[WebAuditID]=[@nId] AND [mqr].[QuestionIdentity]=@IQ.[Questi
| | |--Assert(WHERE:(CASE WHEN [Expr1037]>(1) THEN (0) ELSE NULL END))
| | |--Stream Aggregate(DEFINE:([Expr1037]=Count(*), [Expr1038]=ANY([DB].[dbo].[Question].[Required])))
| | |--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1019]))
| | |--Index Seek(OBJECT:([DB].[dbo].[Question].[IX_Question_QuestionIdentity]), SEEK:([DB].[dbo].[Question].[QuestionIdentity]=[DB].[dbo].[ QuestionResult]
| | |--RID Lookup(OBJECT:([DB].[dbo].[Question]), SEEK:([Bmk1019]=[Bmk1019]) LOOKUP ORDERED FORWARD)
| |--Clustered Index Seek(OBJECT:([DB].[dbo].[ QuestionResultHistory].[PK_ QuestionResultHistory] AS [mqrh]), SEEK:([mqrh].[WebAuditID]=[@nId] AND [mqrh].[QuestionIdentity]=@IQ.[QuestionI
|--Index Seek(OBJECT:([DB].[dbo].[ QuestionResultHistory].[IX_ QuestionResultHistoryIdentity]), SEEK:([DB].[dbo].[ QuestionResultHistory].[QuestionIdentity]=@IQ.[QuestionIdentity] as [
(36 row(s) affected)
StmtText
-------------------------------------------------------------------------------------------------------------------------------------
update s1
set ParentIdentity = s2.CategoryIdentity
from @SubCats s1, @SubCats s2
where s1.ParentId = s2.CategoryGlobalId
(1 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Update(OBJECT:(@SubCats), SET:([ParentIdentity] = @SubCats.[CategoryIdentity] as [s2].[CategoryIdentity]))
|--Table Spool
|--Top(ROWCOUNT est 0)
|--Stream Aggregate(GROUP BY:([Bmk1000]) DEFINE:([s2].[CategoryIdentity]=ANY(@SubCats.[CategoryIdentity] as [s2].[CategoryIdentity])))
|--Nested Loops(Inner Join, WHERE:(@SubCats.[CategoryGlobalId] as [s2].[CategoryGlobalId]=@SubCats.[ParentId] as [s1].[ParentId]))
|--Table Scan(OBJECT:(@SubCats AS [s1]))
|--Table Scan(OBJECT:(@SubCats AS [s2]))
(7 row(s) affected)
StmtText
----------------------------------------------------------------------
Update @SubCats
Set nSubCatsCompleted = 1
where nSubCats = 0
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------
|--Table Update(OBJECT:(@SubCats), SET:([nSubCatsCompleted] = [Expr1004]))
|--Compute Scalar(DEFINE:([Expr1004]=(1)))
|--Top(ROWCOUNT est 0)
|--Table Scan(OBJECT:(@SubCats), WHERE:([nSubCats]=(0)) ORDERED)
(4 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
update s
set nSubCatsCompleted = 1
from @SubCats s
where s.nSubCats > 0
and (select count(*) from @SubCats where parentId = s.CategoryGlobalId and nCatCompleted = 1 and nSubCatsCompleted = 1) = s.nSubCats
(1 row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Table Update(OBJECT:(@SubCats), SET:([nSubCatsCompleted] = [Expr1009]))
|--Compute Scalar(DEFINE:([Expr1009]=(1)))
|--Table Spool
|--Top(ROWCOUNT est 0)
|--Filter(WHERE:(CASE WHEN [Expr1007] IS NULL THEN (0) ELSE [Expr1007] END=@SubCats.[nSubCats] as [s].[nSubCats]))
|--Nested Loops(Left Outer Join, OUTER REFERENCES:([s].[CategoryGlobalId]))
|--Table Scan(OBJECT:(@SubCats AS [s]), WHERE:(@SubCats.[nSubCats] as [s].[nSubCats]>(0)) ORDERED)
|--Compute Scalar(DEFINE:([Expr1007]=CONVERT_IMPLICIT(int,[Expr1020],0)))
|--Stream Aggregate(DEFINE:([Expr1020]=Count(*)))
|--Table Scan(OBJECT:(@SubCats), WHERE:([ParentId]=@SubCats.[CategoryGlobalId] as [s].[CategoryGlobalId] AND [nCatCompleted]=(1) AND [nSubCatsCompleted]=(1)))
(10 row(s) affected)
StmtText
----------------------------------------------
select *
from @SubCats
order by nOrder
(1 row(s) affected)
StmtText
----------------------------------------
|--Sort(ORDER BY:([nOrder] ASC))
|--Table Scan(OBJECT:(@SubCats))
(2 row(s) affected)
StmtText
-----------------------
DROP TABLE #GetCats
(1 row(s) affected)