|
-
Jun 1st, 2000, 08:10 AM
#1
Thread Starter
Addicted Member
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!!!
-
Jun 1st, 2000, 08:25 AM
#2
Hyperactive Member
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
-
Jun 1st, 2000, 09:10 AM
#3
Thread Starter
Addicted Member
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!!!
-
Jun 1st, 2000, 10:10 AM
#4
Hyperactive Member
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. 
-
Jun 1st, 2000, 11:07 AM
#5
Guru
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|