How to get the value of calculated custom field in SQL

Hello All,

 

I am wondering if anyone knows how to query the jira db to get the calculated custom field. I am writing the query and is stucked on this : Below the extract of the query.

SELECT  CAST(I.ID AS NUMERIC) AS ISSUE_ID,
        CONCAT (p.pkey, '-', I.issuenum) as IssueID,
        I.SUMMARY,
        PRJ_MAN.StringValue AS PRJ_MANAGER,
        CUST.CUSTOMVALUE AS CUSTOMER,
        UNIT.CUSTOMVALUE AS BUSINESS_UNIT,
        ISTATUS.PNAME AS STATUS,
        ITYPE.PNAME AS TYPE,
        CAST(ROUND(SUM(AE_PM.WORKLOAD) / 8, 2) AS NUMERIC) AS SKILL_ESTIMATED,
        I.TIMEESTIMATE/28800 AS ISSUE_ESTIMATED,
        DOM_DEV.CUSTOMVALUE as TEAM,
        AE_PM.SKILL AS SKILL_CODE,
        SKILL.TITLE AS SKILL
    
       
  FROM JIRAISSUE I
  LEFT OUTER JOIN PROJECT P ON I.PROJECT=P.ID
  LEFT OUTER JOIN AO_D9132D_ASSIGNMENT_EXT AE_PM ON  I.ID=AE_PM.ISSUE
  LEFT OUTER JOIN AO_82B313_SKILL SKILL ON CAST(SKILL.ID AS NVARCHAR)=AE_PM.SKILL
  LEFT OUTER JOIN ISSUESTATUS ISTATUS ON I.ISSUESTATUS=ISTATUS.ID
  LEFT OUTER JOIN ISSUETYPE ITYPE ON I.ISSUETYPE=ITYPE.ID
  LEFT OUTER JOIN (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName Like 'Customer%'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) CUST ON CUST.ISSUE=I.ID
  LEFT OUTER JOIN (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName Like '%Unit%'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) Unit ON Unit.ISSUE=I.ID
 LEFT OUTER JOIN  (SELECT cfv.issue,  cf.cfname,CFV.StringValue
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   where cf.CFName='Project Manager' ) PRJ_MAN ON PRJ_MAN.ISSUE=I.ID
LEFT OUTER JOIN    (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName='Domain lead'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) DOM_DEV ON DOM_DEV.ISSUE=I.ID
  WHERE p.pname='XXXX'
  GROUP BY
  I.ID,
  AE_PM.SKILL,
  I.SUMMARY,
  I.TIMEESTIMATE,
  p.pkey,
  I.issuenum,
  SKILL.TITLE,
  CUST.CUSTOMVALUE,
  Unit.CUSTOMVALUE,
  ISTATUS.PNAME,
  ITYPE.PNAME,
  PRJ_MAN.StringValue,
  DOM_DEV.CUSTOMVALUE

Any help or guide will be apprecaited.

 

Thank you in advance,

Karim

1 answer

1 accepted

This widget could not be displayed.

SQL is the single worst way to get any information out of an Atlassian application. 

Calculated fields are not held in the database at all.  So you can't get them with SQL, you need to duplicate all the logic behind them.

I'd suggest thinking of a sane way to do your reporting, rather than digging in the database.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

172 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you