Results 1 to 6 of 6

Thread: Not Null Condition

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Posts
    161

    Question

    I am using ADO to access an access database. I am trying to do a count of records where a value is not null. What is the exact sytax for that ?

    What I have is :
    Code:
    "select count(*) from Table where Field1='Some Value' and Field2 is not null"
    Field1 is a string and Field2 is a long integer.

    Any ideas ?... what am I doing wrong ?

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Nothing wrong with your SQl. Are you sure there are actual null values in your database for field2?

  3. #3
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    Try this query

    Code:
    "SELECT COUNT(*) FROM Table WHERE Field1='Some Value' and NOT Field2 IS NULL"
    It works for SQL server

    Remember to watch the Field1 value for containing the ' character, it will let the query up.


    Things I do when I am bored: DotNetable

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Cool never used (*)

    hmm never seen (*)
    i guess that works since 2 people says
    here is how i would do a record count

    SELECT COUNT(PrimaryKey)as Total FROM Table WHERE Field1='SomeValue' AND Field2 IS NOT NULL

    then loop throu the record set, after done
    msgbox "There are " & RS!Total

    hope that helps


  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I think Kovan may have pointed out a floor in the statement. Make sure you have the AS <name> after the COUNT(*) as in the following.

    Code:
    "SELECT COUNT(*) as Total FROM Table WHERE Field1='Some Value' and NOT Field2 IS NULL"
    If not how can you reference the contents of the recordset.


    Things I do when I am bored: DotNetable

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Posts
    161

    Exclamation Solution...

    Thank you all for your help...

    I think I need to thank Microsoft for that one.... NOT !!

    My problem was that the field in my condition was '1310Green'. For some reason, I can use it in the 'Select' part of the SQL, but not in the 'Where'.

    I changed to 'Green1310' and it works perfectly...

    Thanks again !

Posting Permissions

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



Click Here to Expand Forum to Full Width