How can I Create a function that accepts a first and last name and returns a PersonID from the Person table. If no match is found, the function should return -1.
I have tried below, It worked well when the match is found, but when match is not found instead of giving -1 its giving me NULL. Any help on that please
CREATE FUNCTION udf_PersonID(@pn VARCHAR(225)) RETURNS INT AS BEGIN DECLARE @pid INT;
SELECT @pid=personID FROM Person WHERE [email protected] RETURN @pid SELECT @pid=-1 FROM Person WHERE @pn != PersonName RETURN @pid