473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Order of precedence and Logical operators

Microblitz
So here is my dilemma.
This code that I have written produces three options
The first is a VB calender start date and end date for filtering.

The second is a dynamically filled drop down which selects the department or defaults to all departments.

The second is a dynamically filled drop down which defaults to add 'Cells' which is just a two letter code.

To create the default the <All depts> and <All Cells> options I add the first record to the dynamic selection of the records with the <all xxx> row.

At this point a table contains <all depts> and one for all cells followed by all the department codes (or cell codes)

This is then sent to the VB format
Which creates the drop downs.

If the defaults are left selected the report returns everything as expected.

As you can see when I select the department everything works as planned too ...

Here I select BLD as the dept



And it works fine but...

But if I reverse the options and want to find all departments with the cell reference it fails and returns all departments.(I cut this photo short to save space)



Finally if I select a department AND a cell reference it returns the correct result.

If I try to add brackets to force order of precedence visual studio simply automatically removes it with no error message.

I don't understand why it would try to pre-empt me this way and automatically correct my code. I've never had an interpreter or compiler do that to me in any language before.

To explain dbo.wfn_GetSimpleDate is a short date function.

Where the line (PurchaseOrders.DC_001_TXT <> '') appears it is added to correct the fact that these fields do not appear in all records. It's used to strip non modified records.

So the functionality of the WHERE filter is

Get the start and end dates form the user
Filter out non test records
Default of dept selected or changed?
Default of Cell selected or changed?



Expand|Select|Wrap|Line Numbers
  1. SELECT     PurchaseOrders.DC_001_TXT AS Department, PurchaseOrders.DC_002_TXT AS Cell, PurchaseOrders.DC_003_TXT AS Reference, 
  2.                       PurchaseOrders.DC_004_TXT AS FixUse, dbo.wfn_GetUDFNvarchar(N'Element', N'PurchaseOrders', PurchaseOrders.PurchaseOrder) AS Element, 
  3.                       Suppliers.SupplierName, Suppliers.SupplierId, PurchaseOrderItems.Quantity, PurchaseOrderItems.ItemDescription, PurchaseOrderItems.ItemValue, 
  4.                       PurchaseOrderItems.Price, PurchaseOrderItems.ItemNumber, PurchaseOrders.PurchaseOrderId
  5.  
  6.  
  7. FROM         PurchaseOrders INNER JOIN
  8.                       Suppliers ON PurchaseOrders.Supplier = Suppliers.Supplier INNER JOIN
  9.                       PurchaseOrderItems ON PurchaseOrders.PurchaseOrder = PurchaseOrderItems.PurchaseOrder
  10.  
  11.  
  12.  
  13. WHERE     (dbo.wfn_GetSimpleDate(PurchaseOrders.CreatedDate) BETWEEN @DateStart AND @DateEnd) AND (PurchaseOrders.DC_001_TXT <> '') AND (@Department = ' <All Depts>') OR (PurchaseOrders.DC_001_TXT = @Department) 
  14.  
  15.  
  16. AND (@Cell = ' <All Cells>') OR (PurchaseOrders.DC_002_TXT = @Cell)
  17.  
  18. ORDER BY PurchaseOrders.PurchaseOrderId
I have to be doing something really stupid or
this compiler works in a way that i do not fully understand. If I were to create this code in any other language it would work.
May 17 '13 #1
1 1722
I finally got around this by not trying to be too clever and using the multi-select parameters instead of coding my own method for it.
May 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Christos TZOTZIOY Georgiou | last post by:
Hi all, this post contains at the end a handy module that I've used quite often when I wanted to analyse the occasional complex expression and how it was to be evaluated. The function...
3
by: Andrew Durdin | last post by:
In Python, you can override the behaviour of most operators for a class, by defining __add__, __gt__, and the other special object methods. I noticed that, although there are special methods for...
25
by: August Karlstrom | last post by:
Hi, Can someone explain the reason for the warning from GCC below: <shell-session> $ cat test.c #include <stdbool.h> bool a, b, c, d;
2
by: André Hänsel | last post by:
Hi, before I rack my brain about something others have thought about, here my question: Is there any description how to write a parser that evaluates expressions with logical operators like...
10
by: Jonathan | last post by:
Hi all, I'm having an argument with a co-worker about the difference between the & and && operators when applied to boolean operands in C#. His point of view is that the expression (false &...
3
by: gallows | last post by:
Hi, I wondering if there is a standard specification for evalutation of logical expressions. For instance: if (p != NULL && strlen(p) x ) do_something(); If p is actually NULL, should this...
19
by: werdan | last post by:
G'day all I'm bitmapping integers to store combined boolean values and have hit a bit of a snag. I want to be able to turn off certain bits if they they match in a number but not turn them on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.