By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,361 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,361 IT Pros & Developers. It's quick & easy.

Scalar Function

P: 40
FIRST EXAMPLE--CREATE FUNCTION dbo.myFunction()
RETURNS INT
AS
BEGIN
DECLARE @myInt INT
SET @myInt = 1
RETURN @myInt
END

select dbo.myFunction() as 'Simple Number'

This Function is not returning any value,Error is coming
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.myFunction", or the name is ambiguous.

SECOND EXAMPLE--
create function dbo.add1(@num1 Int,@num2 Int)
Returns INT
as
Begin
Return(@num1+@num2)
End

select dbo.add1(10,20) as result

Above function is working fine,but dbo is optional IF I write the above Function without dbo
create function add1(@num1 Int,@num2 Int)
Returns INT
as
Begin
Return(@num1+@num2)
End

select add1(10,20) as result
Then the Function is Contructed successfully , But when I call the function usimg Select statement
Error is there--
'add1' is not a recognized built-in function name.

Plz reply whether its necessary to write owner name to prevent errors.
Apr 8 '08 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
FIRST EXAMPLE--CREATE FUNCTION dbo.myFunction()
RETURNS INT
AS
BEGIN
DECLARE @myInt INT
SET @myInt = 1
RETURN @myInt
END

select dbo.myFunction() as 'Simple Number'

This Function is not returning any value,Error is coming
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.myFunction", or the name is ambiguous.

SECOND EXAMPLE--
create function dbo.add1(@num1 Int,@num2 Int)
Returns INT
as
Begin
Return(@num1+@num2)
End

select dbo.add1(10,20) as result

Above function is working fine,but dbo is optional IF I write the above Function without dbo
create function add1(@num1 Int,@num2 Int)
Returns INT
as
Begin
Return(@num1+@num2)
End

select add1(10,20) as result
Then the Function is Contructed successfully , But when I call the function usimg Select statement
Error is there--
'add1' is not a recognized built-in function name.

Plz reply whether its necessary to write owner name to prevent errors.

During creation, by default, you will own the function. Since sql server can handle multiple objects with the same name as long as it's owned by different owners, you have to specify the who owns the function you are calling. So during creation, owner is optional. In function call, it is required.

-- CK
Apr 9 '08 #2

P: 40
Thx Ck,
dbo is d schems name.Its necessary to have dbo,cz we have the functions with the same name in different schemas.Me right or Wrong?

Can u plz tell me how to create Schema in SQL.
select dbo.myFunction() as 'Simple Number'
Apr 9 '08 #3

ck9663
Expert 2.5K+
P: 2,878
I would assume you're referring to functions, not schema.

Read the full syntax here

--CK
Apr 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.