Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Scalar-valued Functions in SQL

I have migrated a database from oracle, and now have a few Scalar-valued Functions.

However, when I call them, I get an error saying:

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.chk_mgr", or the name is ambiguous.

I'm calling it like this:

SELECT dbo.chk_mgr('asdf') 

What am I doing wrong?

like image 591
Madam Zu Zu Avatar asked Sep 01 '11 19:09

Madam Zu Zu


People also ask

How do you call a scalar valued function in SQL?

When calling a scalar user-defined function we must specify the two-part name i.e. owner name and function name. The dbo stands for the database owner name. We can also invoke a scalar function in SQL Server using the complete three-part name i.e. database name.


1 Answers

Are you sure it's not a Table-Valued Function?

The reason I ask:

CREATE FUNCTION dbo.chk_mgr(@mgr VARCHAR(50))  RETURNS @mgr_table TABLE (mgr_name VARCHAR(50)) AS BEGIN    INSERT @mgr_table (mgr_name) VALUES ('pointy haired boss')    RETURN END  GO  SELECT dbo.chk_mgr('asdf') GO 

Result:

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

However...

SELECT * FROM dbo.chk_mgr('asdf')   mgr_name ------------------ pointy haired boss 
like image 123
8kb Avatar answered Nov 11 '22 07:11

8kb