我做得对吗?
我有一个返钱的功能……
CREATE FUNCTION functionName( @a_principal money,@a_from_date datetime,@a_to_date datetime,@a_rate float ) RETURNS money AS BEGIN DECLARE @v_dint money set @v_dint = computation_here set @v_dint = round(@v_dint,2) RETURN @v_dint END GO Grant execute on functionName to another_user Go
我只是想知道这是否可以转换为iTVF?
我试过这样做但是我收到了一个错误:
CREATE FUNCTION functionName ( @a_principal money,@a_rate float ) RETURNS TABLE AS RETURN SELECT returnMoney = computation_here GO Grant execute on functionName to another_user Go
错误:
Msg 4606,Level 16,State 1,Line 2
Granted or revoked privilege EXECUTE is not compatible with object.
这个函数使用如下:
update table_name set interest = functionName(col1,col2...) where...
提前致谢!
解决方法
标量函数需要EXECUTE权限,但是当您转换为表值函数时,所需的权限将更改为SELECT.
您现在必须GRANT SELECT ON functionName TO another_user;
从BOL开始:
Users other than the owner must be granted EXECUTE permission on a function (if the function is scalar-valued) before they can use it in a Transact-sql statement. If the function is table-valued,the user must have SELECT permissions on the function before referencing it.