1。什么时候需要用到返回一个table型数据,具体语法上需要注意些什么?
2。以下创建函数的语句有什么错误?
use mytest
create function salesbystore
returns table
as
return (select id,name from dbo.person)
...全文
7118打赏收藏
看看这个创建函数的语句有什么错误?
1。什么时候需要用到返回一个table型数据,具体语法上需要注意些什么? 2。以下创建函数的语句有什么错误? use mytest create function salesbystore returns table as return (select id,name from dbo.person)
use mytest
go
if object_id('salesbystore6') is not null
drop function salesbystore6
go
create function salesbystore6()
returns table
as
begin
return (select id,name from dbo.person)
end
go
上面的语句报错?:
Server: Msg 170, Level 15, State 31, Procedure salesbystore6, Line 6
Line 6: Incorrect syntax near 'BEGIN'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'function'.
Server: Msg 178, Level 15, State 1, Line 4
A RETURN statement with a return status can only be used in a stored procedure.
use mytest
go
if object_id('salesbystore6') is not null
drop function salesbystore6
go
create function salesbystore6()
returns table
as
return (select id,name from dbo.person)
go
use mytest
go
if object_id('salesbystore6') is not null
drop function salesbystore6
go
create function salesbystore6()
returns table
as
begin
return (select id,name from dbo.person)
end
go
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'go'.
Server: Msg 111, Level 15, State 1, Line 3
'CREATE FUNCTION' must be the first statement in a query batch.
Server: Msg 178, Level 15, State 1, Line 6
A RETURN statement with a return value cannot be used in this context.