Cancel
Showing results for 
Search instead for 
Did you mean: 

Query with query builder using AND and OR clauses combined

Creator
Creator

Hi all, I have a question regards AND/OR clauses. Exists something like the parenthesis ( ) to establish which lines are the OR? 

For example:

(object_name IS_NULL OR object_ID IS_NULL) AND object_type=XXX

I was trying to make a query of this style but it detects as two options:

1) object_name IS_NULL

or 2) object_ID IS_NULL AND object_type=XXX

The result must be:

1) object_name IS_NULL AND object_type=XXX

or 2) object_ID IS_NULL AND object_type=XXX

Any suggestion?

7 REPLIES

Re: Query with query builder using AND and OR clauses combined

(object_name IS_NULL OR object_ID IS_NULL) AND (object_type=XXX)

 

==

(NOT (object_name IS_NOT_NULL AND object_ID IS_NOT_NULL)) AND (object_type=XXX))

Re: Query with query builder using AND and OR clauses combined

Creator
Creator

ummm... may be I lost something, but I only see AND or OR option in the TC... It's when I am creating a query, in the search criteria section of the query builder. 

Re: Query with query builder using AND and OR clauses combined

As far as I understand the question, you should be able to add logic statements and link them by AND or OR operands. Is it not working that way?

Re: Query with query builder using AND and OR clauses combined

Just guessing here, may be I am wrong. Sentences are evaluated in order, so if many ORs are followed by an AND , the AND will affect all the previous ORs:

 

(NOT (object_name IS_NOT_NULL AND object_ID IS_NOT_NULL)) AND (object_type=XXX))

 

Could be written as:

 (object_name IS_NULL OR object_ID IS_NULL) AND (object_type=XXX)

 

(In fact that is your original sentence)

 

There you have three sentences:

object_name IS_NULL

OR

object_ID IS_NULL

AND

object_type=XXX

 

You could also force:

object_name IS_NULL

AND

object_type=XXX

OR

object_ID IS_NULL

AND

object_type=XXX

 

which is what you had in your explanation.

 

Becareful of my skills in logic algebra, I could have done a wrong step somewhere. Also check in the documentation if the sentences are evaluated in order or in reverse.

Re: Query with query builder using AND and OR clauses combined

Creator
Creator

Thanks for your reply!

I just tried both options that you suggest. The first one:

object_name IS_NULL

OR

object_ID IS_NULL

AND

object_type=XXX

 

is when the detect as only object_name IS_NULL Or (Object_ID IS_NULL and object_type=XXX)

The second one works, but appears twice the object_type parameter to fill in the user's search 

Re: Query with query builder using AND and OR clauses combined

This is being lots of fun!

 

Please, try:

object_type=XXX

AND

object_name IS_NULL

OR

object_ID IS_NULL

 

And let me know how it does.

 

I do not know if a query can be performed over the results of another. If that is the case, the case is closed.

 

Re: Query with query builder using AND and OR clauses combined

Legend
Legend

Teamcenter query builder does not really support grouping of query clauses. It also does not support AND/OR operation precedence.

 

Query clauses are always evaluated in order:

 

((((clause1 <OP> clause2) <OP> clause3) <OP> clause4) <OP> clause5).....

 

You might be able to get simple queries working by reordering those clauses, but for more complex queries it will be hard if not impossible.

---

Thanks and Regards

Yogesh Fegade