To check if input department exists in department table. Function should return Boolean/bit value. (TRUE/1 if exists)
CREATE FUNCTION dbo.fn_CheckDept (@P_DEPTID INT)
RETURNS BIT
BEGIN
DECLARE @v_res BIT
IF EXISTS(SELECT department_id FROM departments WHERE department_id = @p_deptid)
SET @v_res = 1
ELSE
SET @v_res = 0
RETURN @v_res
END
GO
-- test the UDF....
SELECT dbo.fn_CheckDept(200)
SELECT dbo.fn_CheckDept(600)
GO