cancel
Showing results for 
Search instead for 
Did you mean: 

Record Selection formula and Parentehsis

Former Member
0 Kudos

In Crystal Report 2008 I use an "apparently correct" record selection formula with parenthesis like this:

({table1.field1} = 'value1' and {table1.field2} = 'value2') or ({table1.field1} = 'value3' and {table1.field2} = 'value4')


When I run the report it doesn´t show the expected result and if I select "show sql query" I can see the parenthesis has disappeared and due to priority from "and" over "or" the filter is not what I want.

I have tried a lot of parenthesis combinations, and the sql query always deletes it.


How can I solution this?


Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi.

I have been checking the query, and there is no problem with parenthesis deleting.

This:

({table1.field1} = 'value1' and {table1.field2} = 'value2') or ({table1.field1} = 'value3' and {table1.field2} = 'value4')


Is the same as this:


{table1.field1} = 'value1' and {table1.field2} = 'value2' or {table1.field1} = 'value3' and {table1.field2} = 'value4'


Due to priority of "and" over "or".


I don´t know why the first time I didn´t get the expected result and when I saw the trace without parenthesis I thought that was the problem. I tried to repeat the situation and the result is fine. There had to be another reason.


I have done one last test with this formula:


({table1.field1} = 'value1' or {table1.field2} = 'value2') and ({table1.field1} = 'value3' or {table1.field2} = 'value4')


where parenthesis are necessary to keep the sense, and in this case they remain.


My conclusion is that Crystal Report deletes the not necessaries parenthesis, but that  is not a problem.

Thank you for your help and your time.

Former Member
0 Kudos

Hi.

I send a report as you ask me, but I have to advise you that I have tried with different reports and all of them have the same problem.

I usually set the recordselectionformula via vb .net, but after the first problem (seeing the query at SQL Server Profiler) I confirmed the Crystal Report option had the same behavior.

As I said in my first post, I have tried with different logical operators and different parenthesis amount and location and in the final query all my parenthesis disappears.

Thanks.

former_member183750
Active Contributor
0 Kudos

I don't see a mention of any Service packs in this Discussion yet. I would highly recommend SP 6. I'll contact you via Direct message with a link.

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

abhilash_kumar
Active Contributor
0 Kudos

Is this the only record selection criteria you have?

Are there any more conditions separated by 'AND' and/or 'OR'?

-Abhilash

raghavendra_hullur
Active Contributor
0 Kudos

Hi,

Can you share the report with saved data by selecting "Save data with Report" option selected in "File" menu?

Thanks,

Raghavendra