Home > Archive > Microsoft SQL Server forum > October 2005 > simple userdefined function question.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author simple userdefined function question.
parez

2005-10-27, 9:25 am

Hi All!

This is the first time i am tryin to write a sql server 2000 function.
I need to clean up some of my stored procedures..

Can any one please give me skeleton for a userdefined function or
correct my function. I get the following error.

Select statements included within a function cannot return data to a
client.



This returns a bit and it does a query to the database to decide the
value of the bit





CREATE FUNCTION GoodAd
(@adid int,@currentdate datetime)
RETURNS bit
AS
BEGIN
declare @Return bit
select @return = 1

if exists (select null from adqas where adid=@adid)
select @return 0


return @return
end

Erland Sommarskog

2005-10-27, 9:25 am

[posted and mailed, please reply in news]

parez (psawant@gmail.com) writes:
> This is the first time i am tryin to write a sql server 2000 function.
> I need to clean up some of my stored procedures..
>
> Can any one please give me skeleton for a userdefined function or
> correct my function. I get the following error.
>
> Select statements included within a function cannot return data to a
> client.


Looks like a simple syntax error to me:

> CREATE FUNCTION GoodAd
> (@adid int,@currentdate datetime)
> RETURNS bit
> AS
> BEGIN
> declare @Return bit
> select @return = 1
>
> if exists (select null from adqas where adid=@adid)
> select @return 0



I guess you mean:

select @return = 0




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

parez

2005-10-27, 9:25 am

Yes

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com