title: pass table name to sql function
body: <p>I have 2 function </p>
  
  <p>frist find name of employee when Employee.id = id</p>
  
  <pre><code>CREATE FUNCTION FindEmployeeName
   (
      @id bit 
   )
  RETURNS varchar(32)
  AS
  BEGIN
      declare @name varchar(32) 
      set @name=( SELECT Employee.Id FROM Employee WHERE Id=@id)
  RETURN  @name
  END 
  </code></pre>
  
  <p>second find name of Doctor when Doctor.id = id :</p>
  
  <pre><code>CREATE FUNCTION FindDoctorName
   (
      @id bit 
   )
  RETURNS varchar(32)
  AS
  BEGIN
      declare @name varchar(32) 
      set @name=( SELECT Doctor.Id FROM Doctor WHERE Id=@id)
  RETURN  @name
  END 
  </code></pre>
  
  <p><strong>Now, Can I have dynamic function ?</strong></p>
  
  <p><strong>pass table and id  to function and return name?</strong></p>
  
  <pre><code>CREATE FUNCTION FindEmployeeName
   (
      @id bit ,
      @tbl varcahr(32)
   )
  RETURNS varchar(32)
  AS
  BEGIN
      declare @name varchar(32) 
      set @name=( SELECT @tbl.Id FROM @tbl WHERE Id=@id)
  RETURN  @name
  END 
  </code></pre>
  
  <p><strong>Is there a better way?</strong></p>
  
  <p>Edited
  my schema is:
  <img src="https://i.stack.imgur.com/Ang3f.png" alt="enter image description here"></p>