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

Begoña Bonet May 15, 2015

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 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2015

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.

Udo Brand
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.
May 15, 2015

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)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2015

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.

1 vote
Alexandra Topoloaga
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.
May 15, 2015

Hi Begoña ,

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

Regards,
Alexandra 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2015

That won't work, sorry.

Alexandra Topoloaga
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.
May 15, 2015

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2015

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.

0 votes
Begoña Bonet May 15, 2015

Many thanks you two!!!

Suggest an answer

Log in or Sign up to answer