Click to See Complete Forum and Search --> : count number rows that are null
Bebe
Jun 1st, 2000, 08:10 AM
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!!!
Mongo
Jun 1st, 2000, 08:25 AM
Granted this is the Sybase way, but you should be able to translate it accordingly. Hope it helps. :)
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
Bebe
Jun 1st, 2000, 09:10 AM
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!!!
Mongo
Jun 1st, 2000, 10:10 AM
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. ;)
Clunietp
Jun 1st, 2000, 11:07 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.