Thanks Very Much! - Tony C.
On Wed, 7 Apr 2004 14:03:53 +1000, "Andrew John"
[quoted text, click to view] <aj@DELETEmistrose.com> wrote:
>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
>
>"Tony C." <me@here.com> wrote in message news:u4r6709fuihq5g4ld8lct7s13v8kph5qli@4ax.com...
>>
>> 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,
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] "Tony C." <me@here.com> wrote in message news:u4r6709fuihq5g4ld8lct7s13v8kph5qli@4ax.com...
>
> 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!
>
>
>
>