May 25, 2019 at 12:12 pm
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
AS BEGIN
DECLARE @Result BIT = 0
IF EXISTS (SELECT 1 FROM PolicyCoverTypes WHERE CoverType =@CoverType)
SET @Result = 1
RETURN @Result
END
GO
May 25, 2019 at 10:20 pm
Try setting a size for the @CoverType parameter. When you don't specify the size, it defaults to 1
Sue
May 25, 2019 at 10:36 pm
Thank you Sue.
That was indeed the issue
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply