title: Dynamically Changing the Return Type of a Function
body: <p>I am writing a Function that has a return-type which will dynamically change depending on the column which we are passing.
  Here in the following code I am passing the column-value, column-datatype. But I am getting error while running the code.</p>
  
  <blockquote>
    <p>"A RETURN statement with a return value cannot be used in this
    context."</p>
  </blockquote>
  
  <p>If this is not possible then how to change the return type dynamically.
  Kindly suggest solution.</p>
  
  <pre><code>Create Function myFunction(@ColValue varchar(100), @ColReturnType varchar(100))
  RETURNS @ColReturnType
  AS
  BEGIN
      IF(@ColValue = 'xxxxx')
      BEGIN
          return 0
      END
      ELSE
      BEGIN
         return @ColValue
      END
  END
  </code></pre>