2
votes

When I am executing this code I am having this error. Operand type clash: uniqueidentifier is incompatible with int . What are the solutions to remove this error please? Thanks

CREATE FUNCTION [a01].[udf_isUserActive]
(@AccountID INTEGER)
    RETURNS BIT
    AS
    BEGIN
IF (EXISTS (SELECT  accountID
            FROM    [a01].[tbl_userAccounts]
            WHERE   accountID = @AccountID
                    AND isActive = 1))
    RETURN 1;

RETURN 0;
END;
GO
1
The datatype of accountID is presumably uniqueidentifier not integer. - Martin Smith
CREATE FUNCTION [a01].[udf_isUserActive] (@AccountID UNIQUEIDENTIFIER) RETURNS BIT AS BEGIN IF (EXISTS (SELECT accountID FROM [a01].[tbl_userAccounts] WHERE accountID = @AccountID AND isActive = 1)) RETURN 1; RETURN 0; END; GO - BakingCake
This is the good version ^ ? - BakingCake

1 Answers

3
votes

Most probably tbl_userAccounts has an AccountID of type UNIQUEIDENTIFIER and you are trying to compare @AccountID INTEGER with an UNIQUEIDENTIFIER.

Side note: you should provide the entire context: table schema and function call context. It is a big change that calling the function may also lead to performance problems as scalar functions are called per each selected row.