I have created the following function which is to be used for a check constraint.
For some reason it is always returning 0 even if the condition is met.
I have tested it in a normal query and it returns 1 as expected.
Can anyone see any issues with the function?
CREATE FUNCTION IsCoverTypeValid(@CoverType NVARCHAR) RETURNS BIT
DECLARE @Result BIT = 0
IF EXISTS (SELECT 1 FROM PolicyCoverTypes WHERE CoverType =@CoverType)
SET @Result = 1