Using Bracketing in an SQL View

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am using Excel to query a access database, the query changes and if I
look at the query it has brackets around some areas and as it changes so do
the brasckets. can someone tell me the rules/sintax for the brackets any help
will be much appreciated.
Charles
 
Access uses 2 types of brackets in queries:
- square brackets around name of things (fields, tables),
- parentheses to group things together (e.g. phrases in the WHERE clause.)

The square brackets are required if the field/table name contains a reserved
word, a space or other non-text characters, or starts with a number.
Otherwise they are optional.

The parentheses determine the order of precidence for the operations. Access
puts them around field names and phrases in the WHERE clause. In many cases
you can just leave them out.

Where the parentheses do matter is to specify the order of precidence of the
operators. For example, if a, b, and c represent expressions that evaluate
to True or False (e.g. a might be "InvoiceID = 99"), then:
a AND (b OR c)
is not the same as:
(a AND b) OR c
If a is False, and c is True, the first statment is False, while the second
is True. So if you have a mix of operators, use the parentheses to indicate
the order of execution.

Beyond the WHERE clause, there are some cases where the brackets are
required, such as around subqueries, or in certain DDL queries. That's
really beyond the scope of a newsgroup question, but hopefully this summary
helps.
 
Back
Top