Results 1 to 7 of 7

Thread: SQL syntax

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    I need to be able to return with SQL syntax the number of fields within a record that are not null. I can do this with coding with ADO or DAO, but I am using the data environment to create a data report. Thus I need to return the value with SQL. Can someone show me the syntax for this?

    Thanks

    Andrew

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    That's not exactly what I meant. That example returns the total number of recordsin a table where one field is not null. A little clearer explanation:

    I have nine fields in the table. Eight are for grades and observations (the client is a school) which are defined in another table as either passing or not passing. The ninth is the number of observations that have a value of 'passing' in the other table. In the data report I need to show the percentage of passing grades received for each student.

    For example, student Joe Smith receives 5 grades, of which 3 are passing. Joe Smith's percentage will be the total number of passing grades divided by the total number of fields that are not null. The number of grades will vary for each record, so I need to be able to return, for each student, how many of the 8 grade fields have an entry.

    Thanks to all of you guys for the help you have given me in the past. Any help here will be, as always, greatly appreciated!

    Chao

    Andrew

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    You might want to create a temporary table that has the studentid (or whatever the unique key is) and a grade_count field (small integer).

    Then you make 8 passes thru to create/update data.

    Step 1 - Insert into tempTBL (select studentid from table)
    Step2 - Update tempTBL set grade_count=0
    Step3 thru 10 - Update tempTbl set grade_count=grade_count + 1 where studentid in (select keyvalue from table where grade# is not null)

    Step 11 - join tempTBL to your existing table for your reports.

  4. #4
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102

    Post

    SELECT IF(isnull(FLD1), 0, 1)+IF(isnull(FLD2), 0, 1)+IF(isnull(FLDx), 0, 1) as MyCount FROM TABLE

    hope this helps

    cheers

    Andy

    P.S. You might need to change the IF(isnull(FIELD), 0, 1) syntax depending on what flavour of SQL you are using

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    I'm using Jet 4.0 for Access with DAO 3.6 That particular SQL syntax gives me the error that the function IF is not defined.

  6. #6
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    SELECT COUNT(*) FROM [TABLE] WHERE [FIELD] IS NOT NULL

    eg;

    SELECT COUNT(*) FROM tbl_Customers WHERE PhoneNumber IS NOT NULL



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  7. #7
    New Member
    Join Date
    Feb 2000
    Posts
    2

    Post

    Try the inline if function IIF(...). It's standard in all the flavors of VB that I know.

    Originally posted by DrewDog_21:
    I'm using Jet 4.0 for Access with DAO 3.6 That particular SQL syntax gives me the error that the function IF is not defined.

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