SQL 如何执行表值函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6953417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute Table valued function
提问by Shine
I have following function which returns Table .
我有以下函数返回 Table 。
create Function FN(@Str varchar(30))
returns
@Names table(name varchar(25))
as
begin
while (charindex(',', @str) > 0)
begin
insert into @Names values(substring(@str, 1, charindex(',', @str) - 1))
set @str = substring(@str, charindex(',', @str) + 1, 100)
end
insert into @Names values(@str)
return
end
Could any one please explain me how to run this function.
任何人都可以解释我如何运行此功能。
回答by Paul Creasey
A TVF (table-valued function)is supposed to be SELECTed FROM. Try this:
甲TVF(表值函数)应该FROM被选择。尝试这个:
select * from FN('myFunc')
回答by Shiham
You can execute it just as you select a table using SELECT
clause. In addition you can provide parameters within parentheses.
您可以像使用SELECT
子句选择表一样执行它。此外,您可以在括号内提供参数。
Try with below syntax:
尝试使用以下语法:
SELECT * FROM yourFunctionName(parameter1, parameter2)