Results 1 to 5 of 5

Thread: count number rows that are null

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    How could i make an output parameter that will count the number of rows that return a null value.

    I have rows and one of the columns vendor_id can return a null value. I need to count how many have a null value in the query i perform as an output parameter?


    Help!!!

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Granted this is the Sybase way, but you should be able to translate it accordingly. Hope it helps.
    Code:
    CREATE PROC XYZ ( @vid int ) AS
    DECLARE @res int
    SELECT @res = (SELECT COUNT(*) FROM [table_name]
      WHERE vendor_id = @vid AND [mystery_code] = null)
    RETURN

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    okay if i am writing this inside a stored procedured

    I would do this?

    DECLARE @res int output

    SELECT @res = (SELECT COUNT(*) FROM [w]
    WHERE vendor_id = @vid AND [mystery_code] = null)
    RETURN

    what do i put for @vid and what does the mystery code mean. I am a beginner so I am a little or a lot confused?????


    i have a column that is returning some nulls. How do i get a count of just those vendor id's that are null?

    "Hello" -- "there is nobody home"

    help!!!

  4. #4
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Sorry, I didn't mean to add to your confusion. Remember my bias against hardcoding values? That's why I made @vid an input parameter; intent is to maximize the utility of your sp.

    I've forgotten what the field name is for the potential null values; that's what [mystery_code] is intended to be.

    Hang in there, your house is wired. We just need to find the light switch after we get out of the bath tub.


  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    hey bebe, here is the SQL server syntax (I'm not sure if you needed it, but here it is)

    =================================================
    CREATE PROCEDURE spu_CountNulls
    @theCount int output
    AS
    Select @theCount = Count(*) from Customers where fax is null


    and to call it using T-SQL:
    declare @myCount int
    exec spu_CountNulls @myCount output
    print 'Count: ' + cast(@myCount as varchar(10))
    ================================================

    Tom

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