Re: Help with Subquery



On Mon, 21 Apr 2008 02:09:00 -0700, Access To Access wrote:

(snip)
COUNT(ISNULL(cmp_HiddenHearingOverall.LastCRC, 0))

Hi Access To Access,

This might be the problem. The COUNT function will count the number of
non-NULL values. The ISNULL converts NULL (a NULL value) to 0 (a
non-NULL value). If you want to count the number of rows in the result
where LastCRC is not NULL, all you have to do is to remove the ISNULL.

If, on the other hand, you want to count the number of rows where this
is NULL (you might be confused with Access' function IsNull, which is a
Boolean that returns True if the argument is NULL), then you shoould use

SUM(CASE WHEN blahblah.LastCRC IS NULL THEN 1 ELSE 0 END)

If this is not it, then you should provide more details: structure of
the tables involved (posted as CREATE TABLE statements, including all
constraints, propertiies, and indexes; you may omit irrelevant columns
though), sample data (as a series of INSERT statements so that I can
easily recreate the sample data on my test DB), and expected results.

See www.aspfaq.com/5006 for more information.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.



Relevant Pages

  • Re: Extracting Duplicates from SQL Server 2000
    ... Here is the query that I used. ... a few well-chosen rows of sample data (as ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: SQL bug, ISNULL function with smalldatetime
    ... ISNULL ... Columnist, SQL Server Professional ... Is it because the ISNULL function would automatically convert the datetime to a smalldatetime? ... > INSERT testDateQuery ...
    (microsoft.public.sqlserver.programming)
  • Re: Select Expression Operators
    ... Thanks Hugo. ... >>Sorry for what must seem like a dumb question, but I was wondering why I keep ... > SQL Server doesn't offer the same set of functions as Access and it ... > ISNULL will return the second expression if the first is NULL. ...
    (microsoft.public.sqlserver.mseq)
  • Re: Using ISNULL()
    ... "There is a Replace function in VBA"? ... I know how to use JOIN in a query but such usage differs from the VBA ... It sounded to me like the OP's knowledge of an ISNULL ... SQL Server has one such an ISNULL expression: ...
    (microsoft.public.access.queries)
  • Re: Batch Insert
    ... uom, work_type, status,item_number, lot_number, ... NULL, 'UNPLANNED',item_number, lot_number, (qty - ISNULL ... >Columnist, SQL Server Professional ...
    (microsoft.public.sqlserver.server)