SubsID SUMMARY SP Sprint_Name cfname SourceID
10547 AA 6.0 NULL Points 10543
10547 AA NULL GOE 10/03 Sprint 10543
10547 AA NULL GO 10/17 Sprint 10543
I want the SP value to be displayed in the same row where the Sprint_Name is not NULL. So I want my result to be like this
SubsID SUMMARY SP Sprint_Name cfname SourceID
10547 AA 6.0 GOE 10/03 Sprint 10543
10547 AA 6.0 GO 10/17 Sprint 10543
Here is my query
Select ji.ID as SubsID, ji.SUMMARY, it.pname as IssueType,
cfv.NUMBERVALUE as SP, sp.NAME as Sprint_Name,
cf.cfname, ISNULL(il.SOURCE,ji.ID) as SourceID
from
jiraissue as ji
inner join customfieldvalue as cfv on cfv.ISSUE = ji.ID
left outer join issuelink as il on il.DESTINATION = ji.ID or il.SOURCE = ji.ID
left outer join customfieldoption as cfo on cast (cfo.ID as varchar(1000)) = cfv.STRINGVALUE
left outer join AO_60DB71_SPRINT as sp on cast (sp.ID as varchar(1000)) = cfv.STRINGVALUE
left outer join customfield as cf on cf.ID = cfv.CUSTOMFIELD
The problem I am facing is SP and Sprint_Name come from different tables. I thought of using Pivot function but that didnt work. Here is the query with Pivot.
Select *
from
( Select ji.ID as SubsID, ji.SUMMARY
, cfv.NUMBERVALUE as SP, sp.NAME as Sprint_Name,
cf.cfname, ISNULL(il.SOURCE,ji.ID) as SourceID
from
jiraissue as ji
inner join issuestatus as st on ji.issuestatus = st.ID
inner join customfieldvalue as cfv on cfv.ISSUE = ji.ID
left outer join issuelink as il on il.DESTINATION = ji.ID or il.SOURCE = ji.ID
left outer join customfieldoption as cfo on cast (cfo.ID as varchar(1000)) = cfv.STRINGVALUE
left outer join AO_60DB71_SPRINT as sp on cast (sp.ID as varchar(1000)) = cfv.STRINGVALUE
left outer join customfield as cf on cf.ID = cfv.CUSTOMFIELD
where (il.LINKTYPE = 10200 or il.LINKTYPE is null) and it.pname <> 'Epic'
) as SourceTable
pivot
(max(SP)
for cfname IN ([Story Points])
) as PivotTable
The result I get is
SubsID SUMMARY Sprint_Name SourceID Story Points
10547 AA NULL 10543 6.0
10547 AA GO 10/17 10543 NULL
10547 AA GOE 10/03 10543 NULL