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.
“A RETURN statement with a return value cannot be used in this
context.”
If this is not possible then how to change the return type dynamically.
Kindly suggest solution.
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
Return
xmltype instead, that would solve the problem to return arbitrary data that conforms to different contracts.