如何执行表值函数

我有一个返回 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

有人能解释一下如何运行这个函数吗。

164285 次浏览

A TVF (table-valued function) is supposed to be SELECTed FROM. Try this:

select * from FN('myFunc')

You can execute it just as you select a table using SELECT clause. In addition you can provide parameters within parentheses.

Try with below syntax:

SELECT * FROM yourFunctionName(parameter1, parameter2)