SQL Query Not Returning Correct Results

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default SQL Query Not Returning Correct Results

    I am trying to pull all records that are set for mailing and are from every
    state except for Nebraska and some counties in Iowa. It isn't pulling
    correctly. Any help would be greatly appreciated.

    SELECT HS_SATCode.School, HS_SATCode.Add1, HS_SATCode.City, HS_SATCode.State,
    HS_SATCode.[Zip Code], HS_SATCode.county, HS_SATCode.mail_list
    FROM HS_SATCode
    WHERE (((HS_SATCode.State)<>'NE') AND ((HS_SATCode.mail_list)=1)) OR
    (((HS_SATCode.State)='IA') AND ((HS_SATCode.county)<>'Adair' And
    (HS_SATCode.county)<>'adams' And (HS_SATCode.county)<>'audubon' And
    (HS_SATCode.county)<>'buena vista' And (HS_SATCode.county)<>'calhoun' And
    (HS_SATCode.county)<>'carroll' And (HS_SATCode.county)<>'cass' And
    (HS_SATCode.county)<>'cherokee' And (HS_SATCode.county)<>'clay' And
    (HS_SATCode.county)<>'crawford' And (HS_SATCode.county)<>'dickinson' And
    (HS_SATCode.county)<>'fremont' And (HS_SATCode.county)<>'greene' And
    (HS_SATCode.county)<>'guthrie' And (HS_SATCode.county)<>'harrison' And
    (HS_SATCode.county)<>'ida' And (HS_SATCode.county)<>'lyon' And
    (HS_SATCode.county)<>'mills' And (HS_SATCode.county)<>'monona' And
    (HS_SATCode.county)<>'montgomery' And (HS_SATCode.county)<>'o''brien' And
    (HS_SATCode.county)<>'osceola' And (HS_SATCode.county)<>'page' And
    (HS_SATCode.county)<>'pottawattamie' And (HS_SATCode.county)<>'plymouth' And
    (HS_SATCode.county)<>'ringold' And (HS_SATCode.county)<>'sac' And
    (HS_SATCode.county)<>'shelby' And (HS_SATCode.county)<>'sioux' And
    (HS_SATCode.county)<>'tayland' And (HS_SATCode.county)<>'union' And
    (HS_SATCode.county)<>'woodbury') AND ((HS_SATCode.mail_list)=1))
    ORDER BY HS_SATCode.mail_list, HS_SATCode.State, HS_SATCode.county


    hml398 Guest

  2. Similar Questions and Discussions

    1. Complex join = no results (for a query that shouldreturn results)
      I am trying to use a rather complex join that returns many results when the SQL server is queried directly, but returns no results when used on a...
    2. Query results don't display properly in results table.IGNORE PREVIOUS
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
    3. Query results don't display properly in results table.
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
    4. returning results in rows
      I have a db with the fields Day, Month, Year and Message. How can I select all of the messages for the current week starting with sunday and return...
    5. Returning results where the match is not always there!!!
      Hi All I have two tables that I need to match customer data on. The first table holds all of the customers billing info Title Name Address...
  3. #2

    Default Re: SQL Query Not Returning Correct Results

    Wow, that's a lotta brackets. And most of them are unnecessary. Let's reduce
    it a bit.

    WHERE
    (
    HS_SATCode.State)<>'NE' AND HS_SATCode.mail_list =1
    OR (HS_SATCode.State='IA' AND HS_SATCode.county<>'Adair' )
    )

    Can you see how this will send mail to Nebraska?

    Dan Bracuk Guest

  4. #3

    Default Re: SQL Query Not Returning Correct Results

    Microsoft query-builder wizards add extra parentheses like that.
    Good example of the GIGO principle.

    MikerRoo Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139