Groups | Blog | Home
all groups > sql server programming > april 2004 >

sql server programming : count function syntax



Tony C.
4/6/2004 10:00:48 PM

Hi,
I want a to write a function to tell me if there are any rows
in a table that belong to a certain customer.

Like this?

CREATE FUNCTION myFunction ( @cust_no int)
RETURNS int
AS
BEGIN
DELARE @recCount int
SELECT COUNT(*) FROM customers WHERE cust_no = @cust_no
SET @recCount = @@ROWCOUNT
RETURN @recCount
END


This gives me the error message:
"Select statements included within a function cannot return
data to a client" - Ok I don't want to return the result of the
select statement to the client anyway, I just want to count the
nunber of records involved and return that.

Thanks in advance for the help!



Tony C.
4/7/2004 7:18:39 AM
Thanks Very Much! - Tony C.

On Wed, 7 Apr 2004 14:03:53 +1000, "Andrew John"
[quoted text, click to view]
Andrew John
4/7/2004 2:03:53 PM
Tony,

Try:

CREATE FUNCTION myFunction ( @cust_no int )
RETURNS int
AS
BEGIN
DECLARE @recCount int
SELECT @recCount = COUNT(*) FROM customers WHERE cust_no = @cust_no
RETURN @recCount
END

Regards
AJ

[quoted text, click to view]

AddThis Social Bookmark Button