vincem1099
asked on
Function that finds a value in a table
I need a function that will return true in the passed value is in a table. For example:
StationCode Site
100 Site1
200 Site2
300 Site3
400 Site4
Passing a value of 100 would return 1 or true
Passing a value of 150 would return 0 or false
StationCode Site
100 Site1
200 Site2
300 Site3
400 Site4
Passing a value of 100 would return 1 or true
Passing a value of 150 would return 0 or false
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This modification works though
CREATE FUNCTION dbo.udf_LookupSite
(
@StationCode int
)
RETURNS bit
AS
BEGIN
DECLARE @RETURNVALUE BIT
IF EXISTS ( SELECT 1
FROM vSites
WHERE StationCode = @StationCode )
set @RETURNVALUE = CAST(1 AS BIT)
ELSE
set @RETURNVALUE = CAST(0 AS BIT)
RETURN @RETURNVALUE
END
ASKER
Thanks for pointing me in the right direction
ASKER
Msg 455, Level 16, State 2, Procedure udf_LookupSite, Line 20
The last statement included within a function must be a return statement.