Thanks to everyone. Looks like there are lots of ways to make it
work (all of which should have been obvious to me).
On Thu, 28 Dec 2006 20:30:48 -0500, Steve Harp <NoSpam@NoPlace.com>
[quoted text, click to view] wrote:
>Hi Guys,
>
>When I try to create the following UDF I get an error "The last
>statement included within a function must be a return statement.".
>
>create function dbo.udfItExists(@that int)
> RETURNS bit
>AS
>Begin
> if (Exists(select ID
> from my_table
> where this_col = @that))
> return 1;
> else
> return 0;
>End
>
>Is there a way to make this work?
>
>Thanks,
[quoted text, click to view] On Thu, 28 Dec 2006 20:30:48 -0500, Steve Harp wrote:
>Hi Guys,
>
>When I try to create the following UDF I get an error "The last
>statement included within a function must be a return statement.".
>
>create function dbo.udfItExists(@that int)
> RETURNS bit
>AS
>Begin
> if (Exists(select ID
> from my_table
> where this_col = @that))
> return 1;
> else
> return 0;
>End
>
>Is there a way to make this work?
Hi Steve,
And a third way:
CREATE FUNCTION dbo.udfItExists(@that int)
RETURNS bit
AS
BEGIN
RETURN CASE WHEN (EXISTS(SELECT ID
FROM my_table
WHERE this_col = @that))
THEN 1
ELSE 0
END;
END;
--