如果是这样:
//create function dbo.m_fun (@a int)
returns
table
as
begin
return (select * from customers)
end你就用存储过程:
create procedure m_fun
@a int
as
begin
select * from customers
end
//create function dbo.m_fun (@a int)
returns
table
as
begin
return (select * from customers)
end你就用存储过程:
create procedure m_fun
@a int
as
begin
select * from customers
end
returns
table
as
begin
return (select * from customers)
end
--error: Line 7: Incorrect syntax near 'BEGIN'.以上的错误是由于RETURNS 子句指定的 TABLE 不附带列的列表,因而该函数为内嵌表值函数。这种函数的函数体由单个 SELECT 语句构成
所以去掉BEGIN END就没有错了而下面这种标量值函数:
create function dbo.m_fun (@a int)
returns
int
as
begin
return (1)
end
由于标量值函数的函数体可以由多条T-SQL语句构成,因此这样是正确的