Help with query excluding certain combo of rows

  • Hello

    I am trying to exclude from my query rows where Code is either 'GST', 'TAX', 'COMM' and

    rows where Ty is 'A' and 'C' but only where it is also Cr Ind = 'C'

    This is what I have but I know it is not quite right. Can anyone shed light on what I am doing wrong.

    Thanks

    SELECT [Emp Number], SUM(Amount) FROM [" & PayrollSheetName & "$] " & _

    " WHERE Code NOT IN ('GST','TAX', 'COMM') " & _

    " AND (Ty NOT IN ('A','C') AND [Cr Ind] = 'C') " & _

    " GROUP BY [Emp Number] "

    Thanks Brian

    You are never an expert, you are always learning!
  • Try this:

    WHERE

    Code NOT IN ('GST','TAX', 'COMM')

    AND NOT (Ty IN ('A','C') AND [Cr Ind] = 'C'))

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • SELECT [Emp Number], SUM(Amount) FROM [" & PayrollSheetName & "$] " & _

    " WHERE Code NOT IN ('GST','TAX', 'COMM') AND Ty NOT IN ('A','C') AND [Cr Ind] = 'C')

    " GROUP BY [Emp Number] "

    will try this.

  • Thankyou Chris, that was giving me a headache.

    Thanks Brian

    You are never an expert, you are always learning!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply