check for NULL in a column

  • priya__ (6/28/2010)


    Thanks all for your reply,

    I cannot use SUM as I am counting a Key column here and if I use sum it will sum up the columne instead...

    I have to use count only...

    You can use both.

    COUNT with a preaggregate, SUM the COUNTS with a final aggregate, as shown.

    Commonly done with cross-tabs/pivots, see this[/url] excellent paper.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • You can use sum because, if you check the code that Gianluca posted, you're summing 1 or 0, 1 if that row is to be counted, 0 if it's not to be counted. Try it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply