Repository navigation
Expand file tree
/
Copy pathfunc_AM.func.sql
More file actions
55 lines (51 loc) · 1.79 KB
/
Copy pathfunc_AM.func.sql
File metadata and controls
55 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- =============================================
-- Author: Randy Woods
-- Create date: 10-OCT-2023
-- Description: Returns all applicable rows from the ANSWER_MATURITY view.
-- If the assessment has a "sub model" defined, only the answers
-- for the sub model are returned. Otherwise all maturity answers
-- are returned for the assessment.
-- =============================================
CREATE FUNCTION [dbo].[func_AM]
(
@assessmentId int
)
RETURNS @AM TABLE (
[Answer_Id] int
,[Assessment_Id] int
,[Mark_For_Review] bit
,[Comment] nvarchar(max)
,[Alternate_Justification] varchar(2048)
,[Is_Requirement] bit
,[Question_Or_Requirement_Id] int
,[Question_Number] int
,[Answer_Text] nvarchar(50)
,[Component_Guid] uniqueidentifier
,[Is_Component] bit
,[Is_Framework] bit
,[Is_Maturity] bit
,[Custom_Question_Guid] nvarchar(50)
,[Old_Answer_Id] int
,[Reviewed] bit
,[FeedBack] nvarchar(2048)
,[Maturity_Level_Id] int
,[Question_Text] nvarchar(max))
AS
BEGIN
declare @modelId int
select @modelId = model_id from AVAILABLE_MATURITY_MODELS where Assessment_Id = @assessmentId and selected = 1
declare @submodel varchar(20)
select @submodel = stringvalue from DETAILS_DEMOGRAPHICS where assessment_id = @assessmentId and DataItemName = 'MATURITY-SUBMODEL'
if @submodel is null
begin
insert into @AM select * from ANSWER_MATURITY
where Assessment_Id = @assessmentId and Is_Maturity = 1
end
else
begin
insert into @AM select * from ANSWER_MATURITY
where Assessment_Id = @assessmentId and is_Maturity = 1
and Question_Or_Requirement_Id in (select mat_question_id from MATURITY_SUB_MODEL_QUESTIONS where sub_model_name = @submodel)
end
RETURN
END