I'm trying to write a MySQL function which returns whether an username is in my table or not. It's the following:
CREATE FUNCTION UserExists (pUserName VARCHAR(40))
RETURNS BIT DETERMINISTIC
BEGIN
DECLARE rVal BIT;
IF EXISTS (SELECT * FROM Users WHERE userName = pUserName)
THEN SET rVal = 1;
ELSE SET rVal = 0;
END IF;
RETURN rVal;
END;
However, I get an error. Any ideas?