terrajobst / nquery

NQuery is a relational query engine written in C#. It allows you to execute a SELECT query against .NET objects.
MIT License
72 stars 20 forks source link

Searched CASE expression always evaluates to FALSE in JOIN condition #3

Open terrajobst opened 9 years ago

terrajobst commented 9 years ago

Ported from CodePlex

Sample query:

SELECT r.app, r.row AS rrow, o.row as orow, r.mes, r.row = '0'
FROM Result r
    INNER JOIN Other o
        ON r.app = o.app AND CASE WHEN r.row = '0' THEN 1 = 1 ELSE r.row = o.row END

The expression r.row = '0' evaluates correctly in SELECT's select list, but the query's result suggests it always evaluates to FALSE in a JOIN condition (or isn't evaluated at all).

Of course, in this example it's easy to avoid by replacing the whole CASE WHEN with the following logical OR: (r.row = '0' OR r.row = o.row). This works as expected.

terrajobst commented 9 years ago

From user dallmair:

Interesting additional info: My description above is wrong. The CASE WHEN condition evaluates to true if we write 1=1 -- so there seems to be something else quite fishy here. Maybe it's handled correctly by the constant folding, but doesn't work correctly otherwise?

dallmair commented 7 years ago

Works fine in v.Next.