Trying to Learn Functions Returning Null

  • I'm trying to figure out how to do a function that can grab a memberID and spit out their Lastname, Firstname together as a nvarchar and my function below gives me NULL values for membername. Can anyone help me?

    USE

    DatabaseName;

    GO

    CREATE

    FUNCTION dbo.MemberName(@RegMemberID varchar(3))

    RETURNS

    nvarchar(42) WITH EXECUTE AS CALLER

    AS

    begin

    DECLARE @fullname nvarchar(42)

    SELECT @fullname = (LastName + ', ' + FirstName)

    FROM dbo.RegisteredMembers

    WHERE @RegMemberID = RegMemberID;

    RETURN @fullname;

    end

    GO

    USE

     DatabaseName

    GO

  • SELECT @fullname = (ISNULL(LastName,'') + ', ' + ISNULL(FirstName,''))

    NULL+something=NULL

    if there is no RegMemberID it still returns NULL

  • Please do not cross post...

    I wasn't born stupid - I had to study.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply