SQL Assistance - won't select where field is blank.

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL Assistance - won't select where field is blank.

    I'm selecting fields from my main table (ProductData). Each record in that
    table has a SupplierIndex.
    There is a field called SubCategory, which looks up from
    tblSubCatList.iSubCatID but which is not necessarily populated.

    My SQL statement is as follows:

    SELECT ProductData.DacNumber, ProductData.ProdName & ' ' &
    ProductData.SuppliersCatalogueNumber AS ProdName, ProductData.ProdPrice
    FROM tblSubCatList INNER JOIN ProductData ON tblSubCatList.iSubCatID =
    ProductData.SubCategory
    WHERE (((ProductData.SupplierIndex)=1))
    ORDER BY ProductData.SubCategory, ProductData.ProdName;

    However, it only selects those records whose field SubCategory is populated.
    How can I make it pick up those records that have no subcategory?

    Any ideas?

    Cheers

    Matt

    PS. The database is Access 2000 but will be converted to MSSQL once I go
    live.


    Matt Smith Guest

  2. Similar Questions and Discussions

    1. Easy one -- Validating a blank field
      Hi, I have three text fields in a form. At least one of the text fields needs to be populated before the form is submitted. This seems...
    2. Select a list of items into an aliased field when doinga select
      OK I know this is going to sound weird, but I'm wondering if this is possible. I have a task table. (tblTask) These tasks can be assigned to...
    3. Using ASP to Generate SQL Select Statement creates unexpected blank spaces
      "Kaven Tan" wrote in message news:F2CAE485-4014-40C7-9A52-1007B51B290E@microsoft.com... : I am having a problem removing the blank space that is...
    4. Assistance with SELECT BETWEEN
      SELECT area, count(*) * 100/ (select count (*) from traffic) as FROM traffic WHERE datein between "10/1/2003" and "11/30/2003" GROUP by area ...
    5. Detecting Blank form field
      Hi there, I' m getting a (0x80040E2F) error, if I submit my form, with blank textboxes to my update stored procedure. The stored procedure expect...
  3. #2

    Default Re: SQL Assistance - won't select where field is blank.

    Use a LEFT JOIN instead of an INNER JOIN. Is ProductData.SubCategory blank,
    or NULL? There is a very big difference.

    A



    "Matt Smith" <_matt@breathemail.net> wrote in message
    news:bemipd$fpm$1@titan.btinternet.com...
    > I'm selecting fields from my main table (ProductData). Each record in that
    > table has a SupplierIndex.
    > There is a field called SubCategory, which looks up from
    > tblSubCatList.iSubCatID but which is not necessarily populated.
    >
    > My SQL statement is as follows:
    >
    > SELECT ProductData.DacNumber, ProductData.ProdName & ' ' &
    > ProductData.SuppliersCatalogueNumber AS ProdName, ProductData.ProdPrice
    > FROM tblSubCatList INNER JOIN ProductData ON tblSubCatList.iSubCatID =
    > ProductData.SubCategory
    > WHERE (((ProductData.SupplierIndex)=1))
    > ORDER BY ProductData.SubCategory, ProductData.ProdName;
    >
    > However, it only selects those records whose field SubCategory is
    populated.
    > How can I make it pick up those records that have no subcategory?
    >
    > Any ideas?
    >
    > Cheers
    >
    > Matt
    >
    > PS. The database is Access 2000 but will be converted to MSSQL once I go
    > live.
    >
    >

    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: SQL Assistance - won't select where field is blank.


    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:u2W$Tx7RDHA.2676@TK2MSFTNGP10.phx.gbl...
    > Use a LEFT JOIN instead of an INNER JOIN.
    >
    > A
    >
    >
    I tried sticking a LEFT JOIN in the query but the result is the same. What
    is the correct syntax for this?

    (maybe slight variation from last time 'cos I've been messing about)
    SELECT ProductData.DacNumber, ProductData.ProdName & ' ' &
    ProductData.SuppliersCatalogueNumber AS ProdName, ProductData.ProdPrice,
    tblSubCatList.strSubCategory FROM tblSubCatList LEFT JOIN ProductData ON
    tblSubCatList.iSubCatID = ProductData.SubCategory WHERE
    (((ProductData.SupplierIndex)=1))
    ORDER BY tblSubCatList.strSubCategory, ProductData.ProdName;
    >Is ProductData.SubCategory blank, or NULL? There is a very big difference.
    I don't know. If there's no value it's 'cos I haven't entered any data into
    it, and there's no default value or anything.

    Matt


    Matt Smith Guest

  5. #4

    Default Re: SQL Assistance - won't select where field is blank.

    Cracked it. Changed LEFT Join to RIGHT join.

    Been doing a bit of reading on the two methods. Don't quite see why it works
    yet but give me a minute.

    Cheers for your help Aaron. You're a star :)

    Matt


    Matt Smith Guest

  6. #5

    Default Re: SQL Assistance - won't select where field is blank.

    LEFT JOIN includes records from the "left" table (on the left side of the
    JOIN clause) that may or may not be in the "right" table. RIGHT JOIN is the
    opposite.




    "Matt Smith" <_matt@breathemail.net> wrote in message
    news:beml9s$be3$1@hercules.btinternet.com...
    > Cracked it. Changed LEFT Join to RIGHT join.
    >
    > Been doing a bit of reading on the two methods. Don't quite see why it
    works
    > yet but give me a minute.
    >
    > Cheers for your help Aaron. You're a star :)
    >
    > Matt
    >
    >

    Aaron Bertrand - MVP 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