I would like to write a function which query's the database for:
SELECT m.title, m.firstname, m.surname
FROM contact c
LEFT JOIN membership m
ON c.contactID=m.contactID
You see i could have many contacts returned from the above query. I would like to return the results into a variable in the function so that I may use globally.
I want the results of the function to show up like this:
Mr John Test
Mrs Jane Smith
I want to write a function which returns @MemberNames like the example with John and Jane...
This is what i have attempted so far:
CREATE FUNCTION fnGetMemberNames
(
@membershipID int,
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @MemberNames varchar(300)
SELECT m.title, m.firstname, m.surname
FROM contact c
LEFT JOIN membership m
ON c.contactID=m.contactID
WHERE membershipID=@membershipID
RETURN @MemberNames
END