Results 1 to 7 of 7
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a tabel with 7 fileds.
    And this query:

    SQL = "SELECT DISTINCT SPORT FROM ANAGRAFICA WHERE CAUSALE IS NULL OR CAUSALE='MOD' OR NOT CAUSALE='ELIM'"


    now, i want to slect DISTINCT SPORT where in filed (CAUSALE):
    not is present the word "ELIM"
    is present the word "MOD"
    or is blank
    ...????
    In effect get all distinct SPORT with CAUSALE = MOD or CAUSALE is null
    how to?
    Tks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If CAUSALE is either Null or 'MOD', it can't be equal to 'ELIM', so you don't need to include OR NOT CAUSALE='ELIM'.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='796365' date='05-Oct-2009 13:21']If CAUSALE is either Null or 'MOD', it can't be equal to 'ELIM', so you don't need to include OR NOT CAUSALE='ELIM'.[/quote]


    wORK!

    Now have a similar prob with this query:

    SQL = "SELECT COD,DESCRIZIONE FROM ANAGRAFICA WHERE SPORT='" & COD_SPORT & "' AND CAUSALE IS NULL OR CAUSALE='MOD'"

    i want tio get COD and DESCRIZIONE if COD_SPORT =4501

    In the case of image the records are 3

    i dont want to get COD and DESCRIZIONE is CAUSALE=ELIM

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    AND has precedence above OR. To make sure that the OR is evaluated first, you must use parentheses ( ):

    SQL = "SELECT COD,DESCRIZIONE FROM ANAGRAFICA WHERE SPORT='" & COD_SPORT & "' AND (CAUSALE IS NULL OR CAUSALE='MOD')"

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='796369' date='05-Oct-2009 13:56']AND has precedence above OR. To make sure that the OR is evaluated first, you must use parentheses ( ):

    SQL = "SELECT COD,DESCRIZIONE FROM ANAGRAFICA WHERE SPORT='" & COD_SPORT & "' AND (CAUSALE IS NULL OR CAUSALE='MOD')"[/quote]

    TKS For ...you must use parentheses ( ) i dont know this way!
    Tks as usual.
    Now work!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    It's a bit like arithmetics:

    In 3 * 2 + 4, * has precedence above +, so it is evaluated as (3 * 2) + 4 = 6 + 4 = 10.
    If you want to evaluate + first, you have to write it as 3 * (2 + 4). This is evaluated as 3 * 6 = 18.

    Similarly, P AND Q OR R is evaluated as (P AND Q) OR R.
    If you want to evaluate OR first, you have to write it as P AND (Q OR R).

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='796374' date='05-Oct-2009 14:24']It's a bit like arithmetics:

    In 3 * 2 + 4, * has precedence above +, so it is evaluated as (3 * 2) + 4 = 6 + 4 = 10.
    If you want to evaluate + first, you have to write it as 3 * (2 + 4). This is evaluated as 3 * 6 = 18.

    Similarly, P AND Q OR R is evaluated as (P AND Q) OR R.
    If you want to evaluate OR first, you have to write it as P AND (Q OR R).[/quote]

    tks Teacher!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •