Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How can i do this?

Author  Topic 

zakeer
Starting Member

20 Posts

Posted - 2008-03-18 : 08:39:02
Can we use a system defined funtion inside a userdefined function?

I am facing prob ...try to sort it out

create function fncube(@i int)
returns int
as
begin
declare @output int
set @output = power(@i,3)
returns @output
end


when i executing this, it is not getting executed.

help me

Thanks & Regards
Zakeer

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-03-18 : 08:42:45
quote:

create function fncube(@i int)
returns int
as
begin
declare @output int
set @output = power(@i,3)
returns @output
end



should be...

create function fncube(@i int)
returns int
as
begin
declare @output int
set @output = power(@i,3)
return @output
end


Em
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-03-18 : 08:43:44
or just...

create function fncube(@i int)
returns int
as
begin
return power(@i,3)
end



Em
Go to Top of Page

PABluesMan
Starting Member

26 Posts

Posted - 2008-03-24 : 15:39:47
My guess is that you aren't calling the function with the schema prefix. So, instead of calling:

SELECT fncube (3)

... you need to call ...

SELECT dbo.fncube (3)

That is, of course, assuming that the function was created under the [dbo] schema.

Hope this helps!
Go to Top of Page

QAZAFI
Yak Posting Veteran

50 Posts

Posted - 2008-03-24 : 23:51:20
Hi dear
You need to put "return" not "returns" and also you have to tell which schema this function belongs to by default it belong to dbo hope this will help :)

create function fncube(@i int)
returns int
as
begin
declare @output int
set @output = power(@i,3)
return @output
end
SELECT dbo.fncube (3)
Go to Top of Page
   

- Advertisement -