Friday, March 30, 2012

How can I retrieve a function return value from an executed string?

Hello!

Suppose that I have the name of an UDF (@.Function) which returns an scalar value and accepts just one parameter. How can I execute and assign the return value to a variable?

I tried the following, but it did not work:

declare @.Receptor as sql_variant

set @.Receptor=execute('select ' + @.Function + '(10)')

Thanks a lot in advance.The function is not completely qualified (DB name, owner)
Try:

declare @.Receptor as sql_variant
set @.Receptor = database_name.dbo.Function(@.in_param_value)

A user defined function can be used like any other pre-defined function

Originally posted by EMoscosoCam
Hello!

Suppose that I have the name of an UDF (@.Function) which returns an scalar value and accepts just one parameter. How can I execute and assign the return value to a variable?

I tried the following, but it did not work:

declare @.Receptor as sql_variant

set @.Receptor=execute('select ' + @.Function + '(10)')

Thanks a lot in advance.sql

No comments:

Post a Comment