title: Convert scalar function to table function
body: <p>I have a scalar function that returns a value from a select statement if it returns a value for the appropriate variables. If there is no return value, the scalar function returns one of the input parameters as the result.</p>
  
  <p>How can I solve this in a table function?</p>
  
  <p>Can I may be use this:</p>
  
  <pre><code>WITH Param
  AS (
      SELECT ID
          ,Data
      FROM Configuration
      WHERE NAME = 'NameOfConfiguration'
  
      UNION ALL
  
      SELECT NULL
          ,'Default Value'
      )
  SELECT TOP 1 Data
  FROM Param
  ORDER BY ID DESC
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>IF (LEN(ISNULL(@returnvalue, '')) = 0)
  BEGIN
      RETURN @thisvalue
  END
  
  RETURN @returnvalue
  </code></pre>