如何调用返回表数据类型的用户定义函数

时间:2022-05-13 04:11:56

here my code-

在这里我的代码,

create function dbo.emptable()
returns Table
as
return (select id, name, salary from employee)
go

select dbo.emptable()

error: Msg 4121, Level 16, State 1, Line 1 Cannot find either column "dbo" or the user-defined function or aggregate "dbo.emptable", or the name is ambiguous.

错误:msg4121,级别16,状态1,第一行无法找到“dbo”列或用户定义函数或聚合“dbo”。“emptable”,或名称不明确。

while when I run
sp_helptext emptable it shows-

当我运行sp_helptext emptable时,它显示-

create function dbo.emptable()  
returns Table  
as  
return (select id, name, salary from employee) 

it means function exists in database then why it is giving such error?

这意味着函数存在于数据库中,那么它为什么会产生这样的错误呢?

2 个解决方案

#1


3  

Is it because when you select from the function you need to say

是因为当你从函数中选择时你需要说

select * from dbo.emptable() 

not

select dbo.emptable() 

#2


1  

select * from dbo.emptable()

select * from dbo.emptable()

It's a table, after all...

毕竟这是一张桌子……

#1


3  

Is it because when you select from the function you need to say

是因为当你从函数中选择时你需要说

select * from dbo.emptable() 

not

select dbo.emptable() 

#2


1  

select * from dbo.emptable()

select * from dbo.emptable()

It's a table, after all...

毕竟这是一张桌子……