I'm trying to create a custom query for a Document Report for a requirements diagram. I'm having trouble figuring out how to do conditional "WHERE" so that if the "WHERE" is True, display the a value from another table, and if the condition is false to display, "None Specified.
My query works fine until I attempt this last step and I either only get the value for the true statement and ignores the non-matching rows, OR
I get the the value for the true statement and multiple copies of the the non-matching rows. Here's my SQL:
SELECT pkg.Name as Package,
diag.Name as Diagram,
org.Name as Organization,
ref.Name as Guidance,
refa.Default as Guidance_Date,
resp.Name as Responsibility,
resp.Alias as Responsibility_Type,
respreq.Requirement as Description,
IIF(resp.Alias = "Responsibility",
MID(auth.Constraint, INSTR(auth.Constraint, "- ")+2), \\Only if Alias is "Responsibility"
"None Specified") as Authority \\If Alias is "Reference Task"
FROM t_package pkg,
t_diagram diag,
t_object org,
t_diagramObjects dorg,
t_object ref,
t_diagramObjects dref,
t_connector cref,
t_attribute refa,
t_object resp,
t_objectrequires respreq,
t_diagramObjects dresp,
t_connector cresp,
t_objectConstraint auth
WHERE pkg.Package_ID = #PACKAGEID# AND \\ Package
pkg.Package_ID = diag.Package_ID AND \\ Diagram
(dorg.Diagram_ID = diag.Diagram_ID AND \\ Organization
org.Object_ID = dorg.Object_ID AND
org.Object_Type = "Actor") AND
(dref.Diagram_ID = diag.Diagram_ID AND
dref.Ojbect_ID = ref.Object_ID AND
ref.Object_Type = "Artifact" AND
ref.Alias = "Authoritative Document" AND
cref.Start_Object_ID = org.Object_ID AND
cref.End_Object_ID = ref.Object_ID AND
cref.Connector_Type = "Dependency") AND \\ Guidance Document
(refa.Object_ID = ref.Object_ID AND
ref.Name = "Document Date") AND \\ Guidance Document Date
(dresp.Diagram_ID = diag.Diagram_ID AND
dresp.Object_ID = resp.Object_ID AND
resp.Object_Type = "Artifact" AND
cresp.Start_Object_ID = ref.Object_ID AND
cresp.End_Object_ID = resp.Object_ID AND
cresp.Connector_Type = "Dependency") AND \\ Responsibility ; Identified as either "Responsibility" or "Reference_Task"
(respreq.Object_ID = resp.Object_ID) AND \\ Responsibility Description
((res.Alias = "Responsibility" AND
resp.Object_ID = auth.Object_ID AND \\ Find "Authority" if a "Responsibility"
auth.Constraint LIKE "Authority*") OR \\ Extract "Authority" from string, "Authority Reference - MyDocument"
(resp.Alias = "Reference Task") )Ignoring the "Authority" column and logic, I correctly get the following Results:
Package Diagram Organization Guidance Guidance Date Responsibility Responsibility Type Description
------- ------- ------------ -------- ------------- -------------- ------------------- -----------------
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Resp_1 Responsibility "Resp_1 Desc...."
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 2 Reference Task "Ref Tsk 2 Desc."
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 3 Reference Task "Ref Tsk 3 Desc."
The problem comes in when I try to add "Authority". If the Responsibility_Type is "Responsibility", then an row is added to the t_ObjectConstraint table
with a CONSTRAINT = "Authority Reference - MyDocument", but I only want the text AFTER the " - " (e.g., MyDocument).
adding my code to retrieve the Authority document, my expected results are:
Package Diagram Organization Guidance Guidance Date Responsibility Responsibility Type Description Authority
------- ------- ------------ -------- ------------- -------------- ------------------- ----------------- ----------------------
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Resp_1 Responsibility "Resp_1 Desc...." Authority Document 100
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 2 Reference Task "Ref Tsk 2 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 3 Reference Task "Ref Tsk 3 Desc." None Specified
but my actual results are:
Package Diagram Organization Guidance Guidance Date Responsibility Responsibility Type Description Authority
------- ------- ------------ -------- ------------- -------------- ------------------- ----------------- ----------------------
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Resp_1 Responsibility "Resp_1 Desc...." Authority Document 100
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 2 Reference Task "Ref Tsk 2 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 3 Reference Task "Ref Tsk 3 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 2 Reference Task "Ref Tsk 2 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 3 Reference Task "Ref Tsk 3 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 2 Reference Task "Ref Tsk 2 Desc." None Specified
PKG_1 Diag_1 My_Org SOP_10 1/1/2000 Ref Tsk 3 Reference Task "Ref Tsk 3 Desc." None Specified
....Repeats for a couple hundred rows
Note that my data is on a segregated network so data above is notional but representative, and the SQL and results were hand-typed here, so I apologize in advance if there are any misspellings or syntax errors; there are no errors on the segregated networks, other than the logic error I seeking assistance on.
I appreciate any assistance you all might be able to provide.