title: query multiple values in function and return inside 1 variable
body: <p>I would like to write a function which query's the database for:</p>
  
  <pre><code>SELECT m.title, m.firstname, m.surname 
  FROM contact c
  LEFT JOIN membership m
  ON c.contactID=m.contactID
  </code></pre>
  
  <p>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. </p>
  
  <p>I want the results of the function to show up like this:</p>
  
  <pre><code>Mr John Test
  Mrs Jane Smith
  </code></pre>
  
  <p>I want to write a function which returns @MemberNames like the example with John and Jane... </p>
  
  <p>This is what i have attempted so far:</p>
  
  <pre><code>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
  </code></pre>