Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Table Transformer: Check if a column exists. If yes, rename the column.

Shantharam November 21, 2023

I am using 'Table Transformer' macro to pull out JIRA issues and their status using a JQL.

Let's assume that my query returns 3 issues with following statuses:

  1. Defect A with 'Open'
  2. Defect B with 'Closed'
  3. Defect C with 'In Progress'

Also, I am renaming the columns in my query for some reasons, something like:

SELECT T1.'Labels' as 'Project', 
T1.'Count Closed' as 'Closed',
T1.'Count OPEN' as 'Open',
T1.'Count In Progress' as 'In Progress',
From T1 WHERE T1.'Labels' in (<my customer labels for JIRAs>);

And now let's assume that Defect 'C' was moved from 'In Progress' to 'Code Review'.  But now the same query returns the error:

Column does not exist: Count In Progress

This is resulting in frequent page breaks. How can I add a condition in such a way that rename a column only if it exists?

1 answer

1 accepted

4 votes
Answer accepted
Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2023

Hi @Shantharam ,

You may use the COALESCE function for the case. In my example I'm sure that 'Text 1' and 'Text 3' columns are always present but 'Text 2' column may or may not be present:

SELECT
'Text 1' AS 'New 1',
'Text 3' AS 'New 3',
COALESCE('Text 2',"") AS 'New 2'
FROM T*

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events