Forums

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

Use Table Transformer to select columns if existing

Eva Kröger January 27, 2023

Hi there! 

I want to transform a table and select three columns but one of the columns might not exist in some cases. I am using this command: 

SELECT 'Sprint',
'Sum of Story-points a' AS 'Work added',
'Sum of Story-points x' AS 'Work completed',
'Sum of Story-points ‎' AS 'Work remaining'
FROM T*

I thought I could adjust it to something like this:

SELECT 'Sprint',
if exists select t1.'Sum of Story-points a' AS 'Work added',
'Sum of Story-points x' AS 'Work completed',
'Sum of Story-points ‎' AS 'Work remaining'
FROM T*

But it's not working. What could I do here?

1 answer

1 accepted

3 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.
January 27, 2023

Hi @Eva Kröger ,

You may use two options for the case:

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

or

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

Here the 'Text 1' and 'Text 3' columns are always present. The 'Text 2' column is optional (it may be present or not).

If the 'Text 2' column exists, then you'll get its real contents. If it is not present in the source table, then you'll get an empty column in the result table and no errors from the Table Transformer macro.

Hope it helps.

Eva Kröger January 27, 2023

Thanks a lot, that helped!

Like Stiltsoft support likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events