Focal Point
WHERE ISSUE WITH CALCULATION AND 'OR'
December 20, 2012, 10:25 AM
DaveWHERE ISSUE WITH CALCULATION AND 'OR'
Okay people, help me out here...
I know the obvious work-arounds.
I'm just can't figure out why this doesn't work as I think it should.
I like to select all car/models with x or x-1 seats... ...so I made this:
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE SEATS EQ &X OR &X-1
END
But it returns 0 rows...
This works fine:
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE ( SEATS EQ &X ) OR ( SEATS EQ &X-1 )
END
And this works fine too:
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE SEATS EQ 5 OR 4
END
And this doesn't !
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE SEATS EQ 5 OR 5-1
END
Not even like this
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE SEATS EQ 5 OR (5-1)
END
WF can not perform calculation in a WHERE if there is also an OR involved? No matter how many brackets are added...?
For starters I found it strange ( compared to other languages ) that this accepted:
WHERE SEATS EQ 1 OR 4 OR 5
Especially with a NOT added
WHERE NOT SEATS EQ 1 OR 4 OR 5
I'd prefer an syntax error message over some unexplained results...
Anybody any clues?
_____________________
WF: 8.0.0.9 > going 8.2.0.5
December 20, 2012, 10:49 AM
susannahdid you look at the sql?
| In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID |
December 20, 2012, 02:06 PM
Danny-SRLDave,
quote:
-SET &X = 5;
TABLE FILE CAR
PRINT SEATS
BY CAR
BY MODEL
WHERE SEATS EQ &X OR &X-1
END
There are 2 types of ORs:
expression OR expression
field EQ value OR value
In the quoted example, you are using the second type which demands a value not an expression.
Did you see if you got an error message?
I took your code and ran it (WF server 7.7.04M). I got, instead, the whole file!
Wonder why?
Since after the OR there isn't a value, WF looked at it as an expression, the value of which is not zero and treated is as TRUE, hence all the records. Neat, no?
So, why did you get 0 records?...
Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF
December 21, 2012, 03:09 AM
DaveBoth, thanks for the replies.
_______________________________________________________________________
@susannah
What SQL? It's a CAR sample...?!
On a real database this is shown:
08.52.27 BT (FOC2565) THE OBJECT OF IF/WHERE CANNOT BE CONVERTED TO SQL
08.52.27 BT (FOC2566) WHERE WH$$$1 CANNOT BE CONVERTED TO SQL
08.52.27 BT (FOC2583) NON-RELATIONAL OPERAND IS INVALID FOR OPERATION OR
08.52.27 BT (FOC2590) AGGREGATION NOT DONE FOR THE FOLLOWING REASON:
08.52.27 BT (FOC2598) FOCUS IF/WHERE TEST CANNOT BE PASSED TO SQL
Isn't that nice? i.e. it's 'handled' by WF-engine... not by SQL-engine?
_________________________________________________________________________
@Daniel
I know the difference between and operational OR and a logical OR.
But if
WHERE SEATS EQ 2 OR 4 OR 5
works fine...
It seem like it's used as a 'field EQ value OR value'
and it doesn't 'expect' an expression.
Then why does
WHERE SEATS EQ 5-3
does work?
Hence my question:
WF can not handle the -combination- of an expression and the use of 'OR' in a WHERE?
Consider it a logical OR doesn't work either.
WHERE SEATS EQ ( 4 OR 4 ) ( logically 4 OR 4 should always be 4 )
Greets,Dave
_____________________
WF: 8.0.0.9 > going 8.2.0.5
December 21, 2012, 05:21 AM
Alan BI thought Danny answered the question well.
In the documentation:
quote:
In a logical AND or OR test, all field names, test relations, and test values are explicitly referenced and connected by the words OR or AND.
quote:
In a literal OR test, the word OR is repeated between test values of a field name, but the field name itself and the connecting relational operator are not repeated.
As you are mixing logical(&X-1) and literal(&X) expressions, then the field names, test relations and test values MUST be explicitly referenced for the logical expression. So
WHERE SEATS EQ 2 OR 5 OR SEATS EQ 5-1
is the correct way to code.
Alan.
WF 7.705/8.007
December 21, 2012, 07:50 AM
DaveThanks Alan for looking that up...
I got it now.
quote:
In a literal OR test...
I guess it means 2 things:
Part 1: You don't have to repeat the fieldname and connecting relational operator.
Part 2: You can not use expressions as 'test values'.
The last one wasn't that obvious to me...
I assumed the word 'literal' was only used to indicate 'as an test-operator' ( in contrast to 'as a logical-operator' )
I guess my knowledge of other programming languages is throwing me off.
No other language I know allows part 1 and disallows part 2.
I guess WG needs to allow part 1 in order to be able to handle the '1 OR 2 OR 3 OR 4' type of parameters filled by HTML pages.
( Why not use IN ( 1,2,3,4 ) ? Also nicer to display in the header of a report as selected values... )
Thanks all!
And no, I didn't see an error message, coz I didn't get any. ( e.g. like you get with a syntax error or label missing )
The only message you get is what I've posted earlier with TRACE on.
@IBI
quote:
08.52.27 BT (FOC2598) FOCUS IF/WHERE TEST CANNOT BE PASSED TO SQL
Isn't this odd?
There is no problem in passing 'WHERE SEATS EQ 5-1' but the is with 'WHERE SEATS EQ 5-1 OR 5'?
And I found that 'WHERE SEATS IN ( 2 , 5-1 )' translates to SQL : 'SEATS IN (2, 5, -1)'
_____________________
WF: 8.0.0.9 > going 8.2.0.5