How can I define a SQL on which, in where clause, I express that a Database Customfield has no value?

Hi, 

How can I test if a Database Customfield is null in a Dynamic query?

My scenario: 

DBCF1 named customfield_1111: Select * from table1 
This DBCF1 has "Add None option" checked. 

DBCF2 named customfield_2222: 
Select * from table2 where {customfield_1111} is not null  --> it works 
Select * from table2 where {customfield_1111} is null         --> it doesn't work 
Select * from table2 where {customfield_1111}='None'       --> it doesn't work 
Select * from table2 where {customfield_1111}='Ninguno'  --> it doesn't work 

How can I define a SQL on which, in where clause I can indicate "customfield_1111 has no value"? 

Many thanks 

Begoña 

3 answers

1 accepted

1 votes

The short answer is that you can't search directly.  SQL searches columns and rows in a table.

When a custom field is empty, there is no row in the table to search for.  So SQL won't find anything.  That's also why  "select where x = "" " will fail - x does not contain <blank>, x is not there and hence cannot be tested.

I disagree. It is possible to search for non existing records. select * from jiraissue i where not exists (select id from customfieldvalue cfv where cfv.customfield =10000 and cfv.issue = i.id)

Yes, that's what I meant by "directly" - in your SQL, it's indirect - you're taking a list of everything that might be there and dropping the stuff that does exist. You end up with a list of issues, not a list of empty customfields. It is right, of course, but it's not direct.

Hi Begoña ,

Try this, it should work:  
 Select * from table2 where {customfield_1111}  = ''

Regards,
Alexandra 

That won't work, sorry.

I have tested it before posting it. If customfield_1111 is a database information custom field, the given script works.

My mistake, I thought he was talking about normal custom fields, where it absolutely will not work. The DBCFs are an exception, as they hold blanks.

Many thanks you two!!!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,888 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot